I currently have a View in MVC where I pass a single set of data to the view. However, I’ve come across a problem where I am having to use a LINQ query within a For Each loop in the View to pull out additional information from a SQL View of data from another DB.
The error I’m getting is Late binding operations cannot be converted to an expression tree.
The particular snippet I’m encountering the error on is:
<%
For Each oCall In ViewData.Model
%>
<tr>
<td width="290"><a href="/Calls/Details/<%=oCall.CallID %>"><%=oCall.CallSubject %></a></td>
<td width="140"><%=oCall.CallReference %></td>
<td width="130"><%=oCall.CallType.CallTypeName %></td>
<td width="150"><%=oCall.DateOpened %></td>
<%
Dim assigned As String
Dim db As New CustomerServicesModelDataContext
Dim tStore = (From a In db.vStores _
Where a.CompanyID = oCall.CompanyID _
And a.StoreNumber = oCall.StoreID _
Select a).SingleOrDefault()
assigned = tStore.Store
%>
<td width="175">
<%= assigned%>
</td>
</tr>
<%
Next
%>
The error happens twice. First on oCall.CompanyID and then on oCall.StoreID.
Have I missed something?
Thanks for any help in advance.
Liam,
I’ve seen this happen before and i’ve got around it by assigning the values of oCall.CompanyID and oCall.StoreID to variables i.e.:
then plug that into your linq expression. basically, the issue is in trying to resolve the two syncronys calls at the same time.
hope this helps.
jim