I have an entity with a child. How can I display a count of the children for each object in my view?
I've tried:
<% foreach (var item in Model) { %>
<%: item.JobTitle %>
<%: item.EmploymentApps.Count %> Applications
<% } %>
but I'm getting a runtime error:
Compiler Error Message: CS0012: The type 'System.Data.Linq.EntitySet`1<T0>' is defined in an assembly that is not referenced. You m开发者_Python百科ust add a reference to assembly 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
I'm imagining you are having this issue because your domain objects are defined in a separate assembly to your web app (this is good), and your web app previously hasn't had a reference to System.Data.Linq. It's an easy fix, simply add this to your web.config:
<add assembly="System.Data.Linq, Version=3.5.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" />
You get that particular error because the EmploymentApps
property returns an EntitySet<EmploymentApp>
instance. Direct references to types referenced by an intermediatary assembly will generate that exception.
精彩评论