c# - ASP.Net MVC 3 和 System.Data.Entity?

标签 c# .net exception asp.net-mvc-3 entity-framework-4

我正在创建我的第一个 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 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,并且在我的 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/

相关文章:

c# - C# 中的某些内容可以在运行时更改 float 比较行为吗? [x64]

c# - 使 Controller 异步的最简单方法

c# - 尝试后终于没有被调用

c# - 需要使用 javascript 将所选文本设为粗体/斜体/下划线,并使用 C# 保存和检索相同内容

c# - ASP.NET 请求验证程序允许的脚本

c# - Blazor 导出到 Excel

c# - Visual Studio Lightswitch,创建自动更新浏览屏幕的搜索参数?

c# - 如何设置 LUISDialog 转到 .NET 中的“无意图”的最小阈值?

android - 使用 Firebase 无效 Idp 响应的 Google 登录

c# - System.Drawing.Image 异常