首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >动态CRM :Contains<>在CRM中不起作用。

动态CRM :Contains<>在CRM中不起作用。
EN

Stack Overflow用户
提问于 2015-05-05 20:45:56
回答 1查看 253关注 0票数 0

我的代码如下:

代码语言:javascript
复制
var conntionRecord1Id = (from connectionBase in orgServiceContext.CreateQuery("connection")
where connectionBase["record1roleid"] == null
select new { OpportunityId = connectionBase["record1id"] }).Distinct().ToList();

var query =
    from opportunity in orgServiceContext.CreateQuery("opportunity")
    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,
    };

var result = (from f in query.ToList() where conntionRecord1Id.Contains(f.OpportunityId) select f).ToList();

但在上面的查询中,我使用的地方包含了计数为0的内容。即使我在列表中有共同的记录

EN

回答 1

Stack Overflow用户

发布于 2015-05-05 22:06:56

包含Linq扩展方法不知道如何比较复杂对象。

将f.OpportunityId与Guids列表进行比较,而不是与匿名类型的列表进行比较:

代码语言:javascript
复制
var conntionRecord1Id = (from connectionBase in orgServiceContext
.CreateQuery("connection") 
where connectionBase["record1roleid"] == null 
select connectionBase.GetAttributeValue<Guid?>("record1id"))
.Distinct()
.ToList();   

在自定义比较器类中实现IEqualityComparer以比较复杂对象:https://stackoverflow.com/a/6694563/1817350

请记住,调用.ToList()会将所有记录都放入内存中,并且会在大量记录的情况下导致性能问题。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/30053377

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档