2

Is it possible to use the MVC5 Scaffolding to create a new Controller with View, using EntityFramework if the Models and DbContext classes are not in the same namespace.

I have defined the models and dbcontext in 2 separate libraries (Project.Models and Project.DataAccess) and when entering the Add Controller menu the dropdowns for model and datacontext don't contain the classes I'm trying to use.

I have of course referenced them in the project.

neo112
  • 1,703
  • 2
  • 17
  • 39

2 Answers2

2

Just make sure to compile your solution and then go to your MVC project and add reference to your model and dbcontext projects and that should enable you to see the model and dbcontext classes while creating controllers or views via scaffolding.

Tony John
  • 21
  • 3
1

Sometimes MVC project some how catches the first reference. Even you build/rebuild library model, it doesn't update the MVC project. I got same problem and tried these actions:

  1. Unloaded library project and reloaded it into solution
  2. Deleted library model reference from MVC project and added again
  3. Created DbContext class in Library model project.

Then it worked.

Shaahin
  • 1,195
  • 3
  • 14
  • 22