gpt4 book ai didi

vb.net - Linq 嵌套分组

转载 作者:行者123 更新时间:2023-12-04 07:06:21 28 4
gpt4 key购买 nike

我有一个很大的项目表,我需要按类别组织它们,然后按年,然后按月。

项目具有 CategoryID 和 Dated 属性。

我走了这么远:

Dim Items = From Item In DB.Items _
Group By CategoryID = Item.CategoryID _
Into Categories = Group _
Order By CategoryID

但我把:
        Group By Year = Year(Item.Dated) 


        Group By Month = Month(Item.Dated)  

最终结果应该是这样的:
For Each Category in Categories
For Each Year in Category.Years
For Each Month in Year.Months
For Each Item in Month.Items

Next
Next
Next
Next

谢谢

最佳答案

阅读本文后(还有关于此主题的更多信息):

http://msdn.microsoft.com/en-us/vbasic/bb738024.aspx



我想出了:
Dim Items = From Item In DB.Items _
Group Item By CatID = Item.CatID Into Group Select CatID, _
YearGroups = From y In Group _
Group y By YearKey = y.PubDate.Value.Year Into YearGroup = Group _
Select Year = YearKey, _
MonthGroups = From m In YearGroup _
Group m By MonthKey = m.PubDate.Value.Month Into MonthGroup = Group _
Select Month = MonthKey, MonthItems = MonthGroup

关于vb.net - Linq 嵌套分组,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1092725/

28 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com