2011-05-06 85 views
5

我正在创建我的第一个asp.net MVC网站(第3版)。ASP.Net MVC 3&System.Data.Entity?

我正在使用实体框架从我的数据库中获取数据,所以现在,我在我的数据库中有一个电影列表。

我正在尝试做一个显示这些电影列表的页面。

所以,控制器似乎没问题,它返回一个View(IEnumerable)。

在视图中,我指定我的模型的类型:

@model IEnumerable的

电影是与从我EDMX T4模板生成的类,所以它是从EntityObject heriting。

现在,当我尝试显示我的网页,我得到一个错误,说明我说,我已经导入System.Data.Entity的:

Server Error in '/' Application.

Compilation Error

Description: An error occurred during the compilation of a resource required to service this request. Please review the following specific error details and modify your source code appropriately.

Compiler Error Message: CS0012: Le type 'System.Data.Objects.DataClasses.EntityObject' est défini dans un assembly qui n'est pas référencé. Vous devez ajouter une référence à l'assembly 'System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Source Error:

Line 27: Line 28: Line 29:
public class _Page_Views_Movie_List_cshtml : System.Web.Mvc.WebViewPage> { Line 30: Line 31: #line hidden

Source File: c:\Windows\Microsoft.NET\Framework\v4.0.30319\Temporary ASP.NET Files\root\93402ec0\8f8e48f4\App_Web_list.cshtml.9612c299.pwpwk-k5.0.cs Line: 29

但是,我引用这个dll在我的项目中,我有相应的使用在我的控制器中。

我试图把这个用在CSHTML: @using System.Data.Entity的,但它不编译(在System.Data找不到实体)

那么,应该怎么办?

我所有的项目都是.NET 4中(而不是客户端配置文件)

+0

哪个DLL你参考 - System.Data或System.Data.Entity? – 2011-05-06 17:21:09

+0

其中两个 – J4N 2011-05-08 06:37:09

+0

为了让所有的编程爱好者都能卸载.NET Framework语言包以获取英文异常消息。 – 2012-06-25 11:50:41

回答

1

两件事类型枚举 - 1.改变你的模型定义是由穆罕默德提到 - 其更标准的方式以及 2.包括参考: C:\ Program Files \ Reference Assemblies \ Microsoft \ Framework.NETFramework \ v4.0 \ System.Data.Entity.dll

或 在您的实体所在的任何项目中使用POCO Entity.Net模板,以将您从mVc项目中该库的依赖关系中解放出来。

+0

我使用POCO实体发生器,它解决了我的问题 – J4N 2011-05-19 10:48:59

0

请尝试指定如

@model IEnumerable<MyEntityObjectType> 
+0

我试过,但它不会改变任何东西 – J4N 2011-05-18 06:31:58

3

以下行添加到您的web.config

<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> 
+0

我想: <添加组​​件=“System.Data.Entity的,版本= 4.0.0.0,文化=中性公钥= b77a5c561934e089" /> 但它不会改变任何东西 – J4N 2011-05-18 06:35:49

+0

添加此引用允许你指定在你看来@using System.Data.Entity的,它允许你引用实体 – 2012-09-06 13:17:02

1

对于Asp.Net MVC 2和3

<compilation debug="true" targetFramework="4.0" > 
<assemblies> 
     <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> 
    ... 
</assemblies> 

对于ASP.NET MVC 4(.NET4.5)从

变化
<system.web> 
    <compilation debug="true" targetFramework="4.0" /> 

<system.web> 
    <compilation debug="true" targetFramework="4.0" > 
     <assemblies> 
     <add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/> 
     </assemblies> 
    </compilation>