-1

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?

1 Answers1

0

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.

Chris Pratt
  • 232,153
  • 36
  • 385
  • 444
  • Yeah that's what I figured. I have no issue doing it by hand, it's just this project is for an internal data entry application and I can literally accept the basic output it provides without an edit. It would've saved me some time to have it, but I'll live. Thanks for the explanation, Chris. – Tyler Richey Jun 16 '16 at 22:28
  • If you really want to use the scaffolding. You can keep your context and all your entities in the project initially, until everything is scaffolded, and then move them out into a class library after you're done. You'll have to run a find and replace to clean up the namespaces, but that's not difficult. – Chris Pratt Jun 17 '16 at 12:49