LinqDataSource 控制項中的 Key 與 It 關鍵字

在使用 LinqDataSource 控制項進行群組( Grouping )與彙總( Aggregating )資料的時候,有兩個很特殊的關鍵字:Key 與 It

例如以下的 LinqDataSource 宣告:

[code:html] <asp:LinqDataSource   ContextTypeName="ExampleDataContext"   TableName="Products"   GroupBy="new(ProductCategory,Color)"  Select="new(Key,     It As Products,     Max(ListPrice) As MaxListPrice,      Min(ListPrice) As MinListPrice)"  ID="LinqDataSource1"   runat="server"></asp:LinqDataSource> [/code]


Key 關鍵字代表的是 ProductCategory 與 Color 的值,而 It 關鍵字代表的是「群組後」的資料集合。在 MSDN 上 HOW TO:使用 LinqDataSource 控制項分組和彙總資料 文件中的第三個段落「在將資料分組時擷取個別資料錄」你可以看到很完整的範例,他用一個 LinqDataSource 直接完成了兩層的 ListView 的套版,所以你可預見的就是以後程式可以越寫越少了。

相關連結

 

  

此文章由 will 發表於 2008/4/2 上午 12:01:00

永久連結 | 評論 (0) | 此文章的RSSRSS comment feed |

分類: .Net | ASP.NET | C# | LINQ

標籤: , , , , , , ,

收藏: