Scorpion
Scorpion

Reputation: 4585

CRM 2011 LINQ: Invalid ‘where’ condition. An entity member is invoking an invalid property or method

I am running the following LINQ query but it's throwing an error saying "Invalid ‘where’ condition. An entity member is invoking an invalid property or method."

Can anyone suggest me why it's happening. If I remove the 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

Upvotes: 4

Views: 4286

Answers (3)

mtcakmak
mtcakmak

Reputation: 31

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();

Upvotes: 0

Juan Stoppa
Juan Stoppa

Reputation: 510

Try this:

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();    

Upvotes: 0

SLaks
SLaks

Reputation: 887453

CRM's LINQ translator cannot handle the .Equals() method.

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

Upvotes: 4

Related Questions