在连接两个表之后访问所有数据并使用linq对它们进行分组

soo*_*ise 10 c# linq join linq-group

我有两张桌子

TableA
aId
aValue

TableB
bId
aId
bValue
Run Code Online (Sandbox Code Playgroud)

我想通过这两个表来加入这两个表aId,然后将它们分组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};
Run Code Online (Sandbox Code Playgroud)

我的代码无法识别组后的联接.换句话说,分组工作,但连接不起作用(或者至少我无法弄清楚如何在连接后访问所有数据).

Amy*_*y B 22

group和之间的表达式by创建了组元素.

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);
  }
}
Run Code Online (Sandbox Code Playgroud)