Error CS1061 'ApplicationDbContext' does not contain a definition for 'ApplicationUsers' (Fixed)

Visual Studio ASP.NET MVC controller with views and EF template creates db.ApplicationUsers instead of just db.Users. 

Workaround summary:

1. Rename ApplicationUsers to Users

2. Delete the Controller and View

3. Close and Re-open VS and Project. Rebuild.

4. Recreate the Controller!

 

So its in the morning, you said lets scaffold! And you got this error:

image

This happens when you reference a foreign key your “ApplicationUsers” that is used in the IdentityDbContext that inherits IdentityUser.

image

And then when you add a new controller with views using EF the scaffold will generate the ApplicationUsers but its DbSet or property of the object will not be available. 

One workaround is to rename your ApplicationUsers to only “Users”.

image

image

Now this is important, delete the controller and its views folder after renaming. Then you need to close visual studio. 

Open the project once more and rebuild your solution.

You should now be able to scaffold the controller.

image

Happy Scaffoldings!

Author: John Delizo

www.johndelizo.com

Leave a Reply

Your email address will not be published. Required fields are marked *