简体   繁体   中英

MVC5 using scaffolding for classes from other namespaces (referenced DLL)

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.

只需确保编译解决方案,然后转到MVC项目并添加对模型和dbcontext项目的引用即可,这应该使您能够在通过脚手架创建控制器或视图时查看模型和dbcontext类。

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM