簡體   English   中英

Linq錯誤:無效的“ where”條件。 實體成員正在調用無效的屬性或方法

[英]Linq Error : Invalid 'where' condition. An entity member is invoking an invalid property or method

我在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,
            };

錯誤在第二個查詢中引發。

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM