linq-to-sql - ASP.NET MVC 2 + LINQ to SQL - CS0012 编译错误

标签 linq-to-sql asp.net-mvc-2 c#-4.0 asp.net-4.0

在我的数据库架构中,每个论坛都有一个类别,类别可以有多个论坛。我正在尝试使用以下代码列出类别及其各自的论坛:

<%@ Page Title="" Language="C#" MasterPageFile="~/Views/Shared/Site.Master" Inherits="System.Web.Mvc.ViewPage<dynamic>" %>

<asp:Content ID="Content1" ContentPlaceHolderID="TitleContent" runat="server">
    Index
</asp:Content>

<asp:Content ID="Content2" ContentPlaceHolderID="MainContent" runat="server">

    <h2>Index</h2>
    <% foreach (GameSite.Models.Category category in (IEnumerable)ViewData["Categories"])
       { %>
       <%= category.Name %>
       <% foreach (GameSite.Models.Forum forum in (IEnumerable)category.Forums)
          { %>
          <%= forum.Name %>
       <% } %>
    <% } %>
</asp:Content>

当它运行时,我收到以下错误:
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: The type 'System.Data.Linq.EntitySet`1<T0>' is defined in an assembly that is not referenced. You must add a reference to assembly 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.

Source Error:    
Line 11:        { %>
Line 12:        <%= category.Name %>
Line 13:        <% foreach (GameSite.Models.Forum forum in (IEnumerable)category.Forums)
Line 14:           { %>
Line 15:           <%= forum.Name %>

我可以确认System.Data.Linq在我的项目中被引用。

有任何想法吗?

最佳答案

将此添加到 web.config 文件中就可以了。

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

关于linq-to-sql - ASP.NET MVC 2 + LINQ to SQL - CS0012 编译错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2642188/

相关文章:

c# - Linq to SQL 在执行连接时创建额外的子选择

c# - 这是从 DataContext 更新实体的最佳方式吗?

c# - 从 SQL Server 数据库中删除

asp.net-mvc - 如何在 ASP.NET MVC 中将防伪 token 传递给具有 HttpDelete 属性的操作方法?

asp.net-mvc - 如何在编辑器模板中访问父对象?

c# - 测试字符串中的所有可能性

c# - 注册插件和/或工作流时出错。插件程序集不包含所需的类型或无法更新程序集内容

c#-4.0 - 使用 AppDomain.CreateInstanceAndUnwrap 创建类型 T 的实例,然后早期绑定(bind)到类型 T 的方法

c# - 使用 LinqPad 将字符串转换为 Guid

asp.net-mvc - ASP.NET MVC缓存如何处理AJAX请求?