问题
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?
EDIT: 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
});
回答1:
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;
}
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
来源:https://stackoverflow.com/questions/20336653/outer-join-with-linq-causing-groupjoin-error