views:

88

answers:

1

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.

+2  A: 

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

int companyId = oCall.CompanyID;
int storeId = oCall.StoreID;

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

jim
It's gotten me around that problem, however, led me to another.I now receive the error Method 'System.Object CompareObjectEqual(System.Object, System.Object, Boolean)' has no supported translation to SQL'
Liam
ok, no problem, try using this instead: a.CompanyID.Equals(companyId) And a.StoreNumber.Equals(storeId).
jim
Excellent, that did the trick. Thanks.
Liam
Liam - nice one. hope you get around to refactoring that logic into your controller soon :-). all the best..
jim