与Linq的外部连接导致"GroupJoin"错误 [英] Outer join with Linq causing "GroupJoin" error
问题描述
以下联接投影引发错误, 在GroupJoin操作之后必须执行SelectMany操作,其中集合选择器正在调用DefaultIfEmpty方法." 我已经遇到了一些变更,但是还没有弄清楚.有想法吗?
The following join projection is throwing the error, "The 'GroupJoin' operation must be followed by a 'SelectMany' operation where the collection selector is invoking the 'DefaultIfEmpty' method." I've run over a few permutations of changes, but haven't been able to figure it out. Thoughts?
它看起来越来越像这样 可能是Dynamics CRM问题 .我正在访问数据的Xrm模型是由CRM SDK(CRM 2011)生成的.
It's looking more and more like this may be a Dynamics CRM issue. The Xrm models I'm accessing for data have been generated by the CRM SDK (CRM 2011).
var q =
left
.GroupJoin(right,
c => c.Id,
cl => cl.c.Id,
(c, cs) => new { c, cs })
.Where(x=>x.c.Name.Contains("some text"))
.SelectMany(x => x.cs.DefaultIfEmpty(), (x, csubl) =>
new
{
CompanyName = x.c.Name
});
推荐答案
我认为查询语法会更漂亮
i think in query syntax it will be more beautiful
var q = from l in left
join r in right on l.Id equals r.c.Id into groupped
from g in groupped.DefaultIfEmpty()
where l.Name.Contains("some text")
select new {
CompanyName = l.Name;
}
更新
在 msdn 的示例中,具有左连接的示例,因此您可以尝试上面的代码,或者将Where
移到GroupJoin
之前或之后SelectMany
UPDATE
in samples from msdn have sample with left join, so you can try my code above, or move Where
before GroupJoin
or after SelectMany
这篇关于与Linq的外部连接导致"GroupJoin"错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!