ASP.NET MVC LINQtoSQL

时间:2010-08-26 15:40:39

标签: asp.net-mvc

我有一个有孩子的实体。如何在视图中显示每个对象的子项数?

我试过了:

<% foreach (var item in Model) { %>
    <%: item.JobTitle %>
    <%: item.EmploymentApps.Count %> Applications
<% } %>

但是我遇到了运行时错误:

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'.

1 个答案:

答案 0 :(得分:3)

我想象您遇到了这个问题,因为您的域对象是在与您的Web应用程序分开的程序集中定义的(这很好),而您的Web应用程序以前没有引用System.Data.Linq。这是一个简单的修复,只需将其添加到您的web.config:

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

您收到该特定错误,因为EmploymentApps属性返回EntitySet<EmploymentApp>实例。对中间组件引用的类型的直接引用将生成该异常。