MVC 3 &带有实体框架脚手架的 ASP.Net 错误:没有可用的模型类
我试图将 MVC3 与 Code First 的实体框架一起使用,但是 MS Visual Web Developer 2010 中的代码模板生成过程 - 没有在模型文件夹中检测到我的模型 - 给出一条消息 - “没有可用的模型类” - 尽管我确实有想要为其创建控制器的模型类。
我选择的模板选项是“具有读/写操作的控制器和使用实体框架的视图”。
我已卸载并重新安装 Web Developer 2010,但仍然出现相同的错误。
有人知道我该如何解决这个错误吗?
I am trying to use MVC3 with the Entity framework with Code First, but the code Template generation process in MS Visual Web Developer 2010 - is not detecting my Model in the models folder - giving a message - "No Model classes are available" - although I do have model classes for which I want to create controllers.
The templating option I've selected is "Controller with read/write actions and views using the Entity Framework".
I've uninstalled and reinstalled Web Developer 2010, but still having the same error.
Anyone know how I can get around this error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
xixonia 的回应对我有用。我所需要做的就是构建/重建项目,然后一切都按预期进行。
xixonia's response worked for me. All I needed to do was build/rebuild the project and then everything worked as expected.
重建所有并没有为我解决这个问题......直到我关闭 Studio,重新打开并重建所有。然后它就像一个魅力。
Rebuild all did not fix this issue for me... until I closed Studio, reopened and rebuilt all. Then it worked like a charm.
创建模型后必须构建您的项目。
http:// /www.asp.net/mvc/tutorials/hands-on-labs/aspnet-mvc-4-entity-framework-scaffolding-and-migrations
After create models must be build your project.
http://www.asp.net/mvc/tutorials/hands-on-labs/aspnet-mvc-4-entity-framework-scaffolding-and-migrations
我遇到了同样的问题,对我来说,我必须转到实体模型设计器中实体模型的属性并将代码生成策略更改为默认值。它已设置为“无”,因为我尝试过 DbContext 生成器。
I had this same issue and for me I had to go to the properties of the entity model in the entity model designer and change Code Generation Strategy to Default. It had been set to None because I had experimented with a DbContext generator.
我也有同样的问题。
在挖掘我的参考资料时,就在把计算机扔到墙上之前,我发现我在 Web 项目中安装了 EntityFramework 4.1 版本(在创建 MVC 3 项目时的 VS 2010 中)。
我在域项目中安装了 4.3.1(来自 nuget)。
我卸载了它们并从 nuget 重新安装。
现在一切都恢复正常了。
希望这有帮助。
I had this same issue.
While digging through my references, just before throwing the computer against the wall, I found that I had EntityFramework version 4.1 installed in the web project (by VS 2010 when the MVC 3 project was created).
I had 4.3.1 installed in the domain project (from nuget).
I uninstalled both of them and reinstalled from nuget.
Now everything is working again.
Hope this helps.
如果您仍然遇到此问题,请按照以下步骤解决问题:
在此过程中,它会询问您是否要覆盖现有引用(不确定确切的短语)。所以,说“是”来覆盖...
现在尝试将控制器添加到您的项目中,一切都会好起来的。
祝你好运!
If you still have this problem then follow these steps to fix the problem:
During this process, it will ask you whether you want to overwrite the existing references (not sure about the exact phrase). So, say "Yes" to overwrite...
Now try to add the controller to your project and everything will be fine.
Good Luck!