C# Linq错误:无效';其中';条件实体成员正在调用无效的属性或方法
我正在C# Linq错误:无效';其中';条件实体成员正在调用无效的属性或方法,c#,linq,dynamics-crm,C#,Linq,Dynamics Crm,我正在CRM2013中运行Linq查询并抛出错误: 无效的“where”条件。实体成员正在调用无效的属性或方法 我的代码如下 var conntionRecord1Id = (from connectionBase in orgServiceContext.CreateQuery("connection") where connectionBase["record1roleid"] != null
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,
};
erro在第二次查询中被抛出。where子句的左侧必须是属性名,右侧必须是值 这是查询中的问题行:
//lhs必须来自实体
其中ContionRecord1Id.包含(opportunity[“opportunityid”])
Andy Meyers在这里有一个很好的答案:
带有ConditionOperator.In的QueryExpression可能更合适:您没有加入ConctionRecord1ID,因此您的第二个查询没有意义hi@bvrce,var qe=new QueryExpression(“opportunity”);qe.ColumnSet=新列集(“名称”、“机会性ID”、“新地址”邮政编码);qe.Criteria.AddCondition(“opportunityid”,ConditionOperator.NotIn,ConctionRecord1Id.Cast().ToArray());qe.Distinct=true;var结果=proxy.RetrieveMultiple(qe);但这会引发错误:格式化程序在尝试反序列化消息时引发异常:尝试反序列化参数架构时出错。microsoft.com/xrm/2011/Contracts/Services:query.Try在conctionRecord1id上调用.ToList(),在大小写之前:conctionRecord1id.ToList().Cast().ToArray()