我的代码如下:
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的内容。即使我在列表中有共同的记录
发布于 2015-05-05 22:06:56
包含Linq扩展方法不知道如何比较复杂对象。
将f.OpportunityId与Guids列表进行比较,而不是与匿名类型的列表进行比较:
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()会将所有记录都放入内存中,并且会在大量记录的情况下导致性能问题。
https://stackoverflow.com/questions/30053377
复制相似问题