C#LINQ:加入和组

编程入门 行业动态 更新时间:2024-10-10 22:25:32
本文介绍了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:加入和组

本文发布于:2023-06-10 18:39:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/616528.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:LINQ

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!