Search code examples
asp.net-mvcentity-frameworkasp.net-mvc-scaffolding

Entity Framework DB context missing when adding scaffolded item


I originally had my EF class in a project added to the solution with my MVC app project referencing that project directly in the solution. I added a bunch of scaffolded items with no issue. I recently moved my EF project to a separate solution and am pulling the dependency with a NuGet package in my MVC app, and now when I go to add a new scaffolded item, the EF class nor the EF models are available to be added.

The existing scaffolded items still function fine and has no issues. What am I missing here?


Solution

  • The scaffolding in MVC is very finicky. In particular, it only works on entity classes that belong to the context and, importantly for you, the context must reside in the same project as where you are running the scaffold. In other words, unless you're building a very basic MVC project, the scaffolding will very quickly become obsolete.

    The good news is you don't need it. Unless, you're brand spanking new to MVC development, altering the scaffolded controllers, views, etc. will be far more time-consuming than simply creating everything from scratch. There's nothing magical about any of this. A controller is just a class that inherits from Controller. A view is just a text file with a cshtml extension. Everything else is application-specific anyways, meaning that you would have to touch everything that was scaffolded anyways.