Entity Framework 4 和 ASP.NET MVC3 +脚手架问题
最近,我一直在尝试 Visual Studio 2010 的新 .Net 4.0 工具链和新的 Nuget 包管理器。我已经使用了相当多的 MVC3,并尝试了 MVCScaffolding 包,并且印象非常深刻。为了结束这个循环,我决定查看 Entity Framework 4,以真正体验快速原型设计的乐趣。
唉,我无法使用 EF4 创建一个简单的模型,并从该结构成功生成可用的脚手架。
此时我所确定的结构是一个实体“Cake”,具有主键 Id 和字符串 FrostingColor。生成 sql 并将其部署到数据库后,我使用 MVCScaffolding 生成了脚手架。
然后,我编译并运行,并尝试访问我的站点/Cakes/Index 页面。我收到服务器错误:
The type 'MvcApplication1.Models.Cake' is not a supported entity type.
我花了一段时间在谷歌上搜索其他有此问题的人,但无法弄清楚它的情况。有没有人尝试过这个,或者碰巧知道可能是什么原因造成的?
谢谢!
Recently I've been trying out the new .Net 4.0 toolchains for Visual Studio 2010, and the new Nuget Package Manager. I've played with MVC3 a fair bit, and tried out the MVCScaffolding package, and was pretty impressed. To close the loop, I decided to check out Entity Framework 4 to really get into the rapid prototyping funness.
Alas, I am not able to create a simple model with EF4, and successfully generate a usable scaffold from that structure.
The structure I have scoped down to at this point is an entity "Cake", with a primary key Id and a string FrostingColor. After generating the sql and deploying it to the database, I generated the scaffold with MVCScaffolding.
Then, I compile and run, and attempt to visit my site/Cakes/Index page. I receive the server error:
The type 'MvcApplication1.Models.Cake' is not a supported entity type.
I've spent a while googling for others with this problem, but can't make heads or tails of it. Has anyone tried this, or happens to know what might be causing it?
Thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
查看 MVC 音乐商店教程。它使用 EF CodeFirst 和 MVC3。您还可以查看 MVC 脚手架:标准用法
Have a look at the MVC Music Store Tutorial. It uses EF CodeFirst and MVC3. You can also take a look at MVC Scaffolding: Standard Usage
据我目前所能理解的,从 edmx 生成的类不能用作实体。安装 ADO.NET C# POCO 实体生成器并为我的“蛋糕”实体生成适当的 POCO 类后,一切似乎都工作正常。我仍然困惑为什么从“entityobject”继承的部分类不能用作实体,但至少有一个可行的解决方案来从给定的数据库模型生成快速原型。
相关资源:
As best as I can understand at this point - the generated classes from the edmx cannot be used as an entity. After installing the ADO.NET C# POCO Entity Generator and generating the appropriate POCO class for my "cake" entity, everything seems to work fine. I'm still baffled by why the partial classes inheriting from "entityobject" can't be used as an entity, but at least have a workable solution to generate a quick prototype from a given database model.
Relevant Resources: