CRM 2011 LINQ: Invalid 'where condition. An entity member invokes an invalid property or method

I run the following LINQ query, but it throws an error with the message "Invalid" where condition. An entity member invokes an invalid property or method.

Can someone please tell me why this is happening. If I remove conn.Record2Id.LogicalName.Equals("account")

from WHERE

it returns the result, but I can see LogicalName = account in quick view

.

var connections = (from conn in context.CreateQuery<Connection>()                              
                  where (conn.Record1Id.Id.Equals(incidentId) 
                  && conn.Record2Id.LogicalName.Equals("account") 
                  && conn.StateCode == 0)
                  select conn).FirstOrDefault();

      

Thanks in Advance

+3


source to share


3 answers


The CRM LINQ translator cannot handle the method .Equals()

.



Change it to conn.Record2Id.LogicalName == "account"

+4


source


Try the following:



var connections = (from conn in context.CreateQuery<Connection>()                              
              where conn.Record1Id != null 
              && conn.Record1Id.Id == incidentId 
              && conn.Record2Id != null 
              && conn.Record2Id.LogicalName == "account" 
              && conn.StateCode.Value == 0
              select conn).FirstOrDefault();    

      

0


source


Interesting, but try this :)

var connections = (from conn in context.CreateQuery<Connection>()                              
                  where (conn.Record1Id == new EntityReference("account",incidentId) 
                  && conn.StateCode == 0)
                  select conn).FirstOrDefault();

      

0


source







All Articles