我正在运行以下LINQ查询,但它抛出了一个错误,说"无效的'where'条件。实体成员正在调用无效的属性或方法。"
有人能告诉我为什么会发生这种事吗。如果我从WHERE
中删除conn.Record2Id.LogicalName.Equals("account")
,它会返回结果,但我可以在quick view
中看到LogicalName=帐户。
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();
提前感谢
CRM的LINQ转换器无法处理.Equals()
方法。
将其更改为conn.Record2Id.LogicalName == "account"
试试这个:
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();
有趣,但试试这个:)
var connections = (from conn in context.CreateQuery<Connection>()
where (conn.Record1Id == new EntityReference("account",incidentId)
&& conn.StateCode == 0)
select conn).FirstOrDefault();