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!

Chain Commands in Package Manager Console and PowerShell

So its late, I am in a hurry and am very hungry. I needed this to be quick.

image

You can actually “Chain” or have sequential commands in one line using PowerShell. To do this use a semicolon “;” in each statement or command.

What it does is execute each statement or command then brings back the cursor to you after the last command was executed.

Since Package Manager Console uses PowerShell. In fact, a simple get-command will display a long list of commands and modules (As I demonstrate… a long list, not a good idea without any filters on get-command on a development computer).

image

So using PowerShell’s Sub expressions, you can also chain your commands like enabling the migration and then adding an initial migration then finally update the database on one command inside package manager console.

It’s the little things.