2010-10-05 55 views
2

一鍵我有一個集合如下返回字典的子集的複雜類型與LINQ的

Private _bankRates As Dictionary(Of RateSourceBank.Key, RateSourceBank) 

哪裏RateSourceBank.Key簡直是

Public Class Key 
    Public RateType As String 
    Public EffectiveDate As DateTime 
End Class 

我怎樣才能檢索到的子集_bankRates每個RateType有多個EffectiveDate?

不幸的是,我發現所有類似的例子都是用C#編寫的,而我對LINQ的翻譯比較簡單,尤其是對於語法組來說。下面

Dim ratesWithDuplicates = From rates In _bankRates 
          Group rates By rates.Key.RateType 
          Into grp() 
          Where grp.Count > 1 

查詢我收到錯誤:

Definition of method 'grp' is not accessible in this context

回答

2

這裏是你正在尋找

Dim ratesWithDuplicates = 
    From rates In _bankRates 
    Group rates By rates.Key.RateType Into Group 
    Where Group.Count() > 1 

表達/關鍵字Group表示該集合的片段。您可以使用name = Group語法給它一個不同的名稱

Dim ratesWithDuplicates = 
    From rates In _bankRates 
    Group rates By rates.Key.RateType Into someName = Group 
    Where someName.Count() > 1