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!

Advertisements

Published by

johndelizo

John is currently creating digital assets that protects people and their future, a technical trainer and a full time geek specializing on development and deployment of innovations created with .NET framework on Windows platform as well as Windows infrastructure projects. He is the primary contact of the Philippine Windows Users Group, a contributor at the Microsoft Philippines Community forums and regularly conducts community sessions as well as other Microsoft technology events. John owns the Busy Saving The World Techblog.

One thought on “Error CS1061 ‘ApplicationDbContext’ does not contain a definition for ‘ApplicationUsers’ (Fixed)”

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s