模型第一脚手架在 ASP.NET MVC3 应用程序中不起作用
我正在使用脚手架从数据库模型构建一个控制器。
后端的数据库是 SQL Azure,尽管我不确定这是否重要。
我输入了连接字符串并进行了测试,它有效。我向我的模型添加了一个新的 ADO.Net 实体数据模型,它创建了映射,当我打开创建的模型时,我可以查看表结构和 FK,它看起来是正确的。
我构建了解决方案,以便新模型可用。
我确保我拥有最新版本的实体框架,并从 NuGet 下载了 MvcScaffolding。
当我使用实体框架添加具有读/写操作和视图的新控制器时,出现以下错误:
未映射类型“Website.Models.App.Application”。 检查是否未使用 Ignore 方法或 NotMappedAttribute 数据注释显式排除该类型。 验证该类型是否被定义为类,不是原始类型、嵌套类型或泛型类型,并且不是从 EntityObject 继承。
当我尝试使用 MvcScaffolding:具有读/写操作和视图的控制器,使用 EF 数据访问代码添加相同的控制器时,我在此步骤中没有收到错误,但是当我导航到新控制器的索引视图时,我得到了同样的错误。
关于导致此错误的原因有什么想法吗?我已经寻找了很长时间的解决方案,但一切都是空的。谢谢。
I am building a controller using scaffolding, from a database model.
The database in the backend is SQL Azure, although I am not sure if that matters.
I entered the connection string, and tested, and it works. I added a new ADO.Net Entity Data Model to my models, and it created the mappings, and I can view the table structure and the FKs when I open the created model, and it looks correct.
I built the solution so the new model is available.
I made sure I have the latest version of Entity Framework, and downloaded the MvcScaffolding from NuGet.
When I add new controller with read/write actions and views, using Entity Framework, I get the following error:
The type 'Website.Models.App.Application' was not mapped.
Check that the type has not been explicitly excluded by using the Ignore method or NotMappedAttribute data annotation.
Verify that the type was defined as a class, is not primitive, nested or generic, and does not inherit from EntityObject.
When I try to add the same controller using MvcScaffolding: Controller with read/write actions and views, using EF data access code, I do not get an error at this step, but when I navigate to the Index View of the new controller I get the same error.
Any ideas about what is causing this error? I have seached long for a solution but everything is coming up empty. Thank you.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
如果 Visual Studio 2010 中的在线模板无法提供 Net DbContext Generator,请安装 Net DbContext Generator
Install Net DbContext Generator, if not available from online templates in your Visual Studio 2010
在实体设计器(.edmx 文件)中,右键单击空白区域,单击“添加代码生成项”,选择“ADO.NET DbContext Generator”为其命名,单击“添加”。 >>不记得为什么你必须这样做:-(但它为我解决了同样的问题。
in the entity designer (.edmx file), right click on a blank area, click 'Add Code Generation Item', select 'ADO.NET DbContext Generator' give it a name, click add. >>cant remember why you have to do this :-( but it fixed the same problem for me.
您可能将您的类嵌套在主类中:
You probably nested your your classes in the main class: