我正在创建我的第一个 asp.net MVC 网站(版本 3)。
我正在使用 Entity Framework 从我的数据库中获取数据,所以现在,我的数据库中有一个电影列表。
我正在尝试制作一个显示这些电影列表的页面。
所以, Controller 似乎没问题,它返回一个 View(IEnumerable)。
在 View 中,我指定了模型的类型:
@model IEnumerable
Movie 是使用我的 edmx 中的 T4 模板生成的类,因此它继承自 EntityObject。
现在,当我尝试显示我的页面时,出现错误,提示我必须导入 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 hiddenSource 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,并且在我的 Controller 中有相应的使用。
我试着把它用在 cshtml 中: @using System.Data.Entity 但它没有编译(在 System.Data 中找不到实体)
那我该怎么办呢?
我所有的项目都是 .Net 4(不是客户端配置文件)
最佳答案
将以下行添加到您的 web.config
<add assembly="System.Data.Entity, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
关于c# - ASP.Net MVC 3 和 System.Data.Entity?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5913024/