求助 结果集交叉查询

Izanagi 2013-01-18 02:11:47
感谢帮助 !




如图所示, 现有结果集1和结果集2, 需要使用linq合并成一个结果集, 其中字段ABCD为数字类型.
请尽量使用1条linq查询出来
...全文
160 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
Izanagi 2013-01-18
  • 打赏
  • 举报
回复
引用 1 楼 hjywyj 的回复:
var ary = (from t1 in listA from t2 in listB where t1.key == t2.key select new { key = t1.key, a = t1.a, b = t1.b, c = t2.c, d = t2.d }).Union( listA.Where(t => listB.Cou……
大侠好身手! 感谢
  • 打赏
  • 举报
回复
var ary = (from t1 in listA from t2 in listB where t1.key == t2.key select new { key = t1.key, a = t1.a, b = t1.b, c = t2.c, d = t2.d }).Union( listA.Where(t => listB.Count(tt => tt.key == t.key) == 0).Select(t => new { t.key, a = t.a, b = t.b, c = 0, d = 0 }).Union(listB.Where(t => listA.Count(tt => tt.key == t.key) == 0).Select(t => new{key=t.key,a=0,b=0,c=t.c,d=t.d})));

8,497

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 LINQ
社区管理员
  • LINQ
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧