我在CRM2013
中运行Linq查询并抛出错误:
'where'条件无效。实体成员正在调用无效的属性或方法。
我的代码如下
var conntionRecord1Id = (from connectionBase in orgServiceContext.CreateQuery("connection")
where connectionBase["record1roleid"] != null
select connectionBase["record1id"]
).Distinct();
var query = from opportunity in orgServiceContext.CreateQuery("opportunity")
where conntionRecord1Id.Contains(opportunity["opportunityid"])
orderby opportunity["createdon"] ascending
select new
{
Topic = opportunity.Attributes.Contains("name") == true ? opportunity["name"] : null,
OpportunityId = opportunity.Attributes.Contains("opportunityid") == true ? opportunity["opportunityid"] : null,
PostalCode = opportunity.Attributes.Contains("new_address_postalcode") == true ? opportunity["new_address_postalcode"] : null,
};
错误是在第二次查询中抛出。
答案 0 :(得分:1)
where子句的左侧必须是属性名称,右侧必须是值。
这是查询中的问题行:
// lhs must be something from the entity
where conntionRecord1Id.Contains(opportunity["opportunityid"])
Andy Meyers在这里有一个很好的答案:https://stackoverflow.com/a/15720786/1817350
使用ConditionOperator.In的QueryExpression可能更合适:https://stackoverflow.com/a/21093122/1817350