tags:

views:

45

answers:

1

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 must add a reference to assembly 'System.Data.Linq, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089'.
A: 

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.

Matthew Abbott