有许多看似相关的Linq问题,但是快速浏览内容似乎并没有特别回答我的问题,因为我有限的情报需要掌握。
我们有一个名为PropertyInteractions
的表,其中通过线程id存储线程消息,线程标识符是初始交互记录的Id
。鉴于以下Linq查询(检索有关用户的所有交互),我如何将interactions
拆分为PropertyInteraction
分组的Id
列表?
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)
答案 0 :(得分:4)
听起来你只是想要:
Group interaction By interaction.Id Into Group
有关详细信息,请参阅docs for the Group By clause。 (看起来它与类似的C#查询表达式语法略有不同; VB专家可能会提供更详细的建议。)
答案 1 :(得分:4)
Dim groupedInteractions = interactions.GroupBy(Function(i) i.Id)