我有一个简单的问题。我想使用来自左外连接的分组值。 但我得到异常“未设置对象引用...”。 我哪里错了,你能帮我吗?
我的代码;
var query = from a in aList
join b in bList n a.id equals b.id into bJoin
from bVal in bJon.DefaultIfEmpty()
group new { a.x, a.y, a.z, bVal.x } by a.q into grp
select new {
q = a.q,
....
x = grp.Max(max=>max.a.x)!=null ? grp.Max(max=>max.b.x) : string.Empty
};
最佳答案
我解决了问题。您可以在下面找到解决方案代码;
var query = from a in aList
join b in bList n a.id equals b.id into bJoin
from bVal in bJon.DefaultIfEmpty()
group new { a.x, a.y, a.z,
newX = (bVal == null ? string.Empty : bVal.x)
}
by a.q into grp
select new {
q = a.q,
....
x = grp.Max(max=>max.a.x)!=null ? grp.Max(max=>max.newX) : string.Empty
};
关于c# - 来自左外连接的分组值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/56627025/