本文介绍了C#LINQ:加入和组的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我有两个表
TableA aId aValue TableB bId aId bValue我想加入这些通过援助两个表,并从那里通过bValue它们分组
I want to join these two tables via aId, and from there, group them by bValue
var result = from a in db.TableA join b in db.TableB on a.aId equals b.aId group b by b.bValue into x select new {x};
我的代码无法识别的组后加入。换句话说,分组工作,但加入不(或至少我无法弄清楚如何在连接后访问所有的数据)。
My code doesn't recognize the join after the group. In other words, the grouping works, but the join doesn't (or at least I can't figure out how to access all of the data after the join).
任何帮助,将不胜感激。我是一个的n00b。
Any help would be appreciated. I'm a n00b.
推荐答案的组之间的表达和在按创建组元素。
var result = from a in db.TableA join b in db.TableB on a.aId equals b.aId group new {A = a, B = b} by b.bValue; // demonstration of navigating the result foreach(var g in result) { Console.WriteLine(g.Key); foreach(var x in g) { Console.WriteLine(x.A.aId); Console.WriteLine(x.B.bId); } }更多推荐
C#LINQ:加入和组
发布评论