Reputation: 4585
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
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
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
Reputation: 887453
CRM's LINQ translator cannot handle the .Equals()
method.
Change it to conn.Record2Id.LogicalName == "account"
Upvotes: 4