繁体   English   中英

使用Linq将列表分成几组

[英]Split list into sets using Linq

有很多看似相关的Linq问题,但是快速浏览内容似乎并不能完全回答我的问题,以至于我的智力有限。

我们有一个名为PropertyInteractions的表,其中通过线程ID存储线程消息,该线程标识符是初始交互记录的Id 给定以下Linq查询(检索与用户有关的所有互动),我如何将interactions分为Id分组的PropertyInteraction列表?

Dim interactions = (From interaction In propertyItem.PropertyInteractions _
                    Where (interaction.SenderId = CurrentUser.ID OrElse _
                           interaction.RecipientId = CurrentUser.ID) AndAlso _
                           interaction.InteractionType = InteractionType.ViewRequest _
                    Order By interaction.ThreadId _
                    Select interaction)

编辑:

鉴于乔恩(Jon)的投入,这是我目前的想法,尽管它可能会发生变化。

Dim interactions = _
    (From interaction In propertyItem.PropertyInteractions _
     Where (interaction.SenderId = CurrentUser.ID OrElse _
            interaction.RecipientId = CurrentUser.ID) AndAlso _
            interaction.InteractionType = InteractionType.ViewRequest _
     Order By interaction.ThreadId _
     Group interaction By interaction.ThreadId Into Group)

听起来就像您只想要:

Group interaction By interaction.Id Into Group

有关更多信息,请参阅文档中的Group By子句 (看起来它的工作方式与类似的C#查询表达式语法略有不同; VB专家可能会提供更多详细的建议。)

Dim groupedInteractions = interactions.GroupBy(Function(i) i.Id)

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM