简体   繁体   English

MVC5将脚手架用于其他名称空间中的类(引用的DLL)

[英]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. 如果Models和DbContext类不在同一个命名空间中,是否可以使用MVC5脚手架通过EntityFramework使用View创建新的Controller。

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. 我已经在2个独立的库(Project.Models和Project.DataAccess)中定义了模型和dbcontext,进入“添加控制器”菜单时,model和datacontext的下拉列表不包含我要使用的类。

I have of course referenced them in the project. 我当然在项目中引用了它们。

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

Sometimes MVC project some how catches the first reference. 有时MVC计划一些如何捕捉第一个参考。 Even you build/rebuild library model, it doesn't update the MVC project. 即使您构建/重建库模型,它也不会更新MVC项目。 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 从MVC项目中删除库模型参考,然后再次添加
  3. Created DbContext class in Library model project. 在图书馆模型项目中创建了DbContext类。

Then it worked. 然后它起作用了。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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