views:

29

answers:

1

I have a collection as follows

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

Where RateSourceBank.Key is simply

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

How can I retrieve a subset of _bankRates that have more than one EffectiveDate per RateType?

Unfortunately all similar examples I find are in C# and I fond the LINQ translation somewhat less than straightforward, especially when it comes to the group by syntax, e.g. with query below

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

I receive error:

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

+1  A: 

Here is the snippet you're looking for

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

The expression / keyword Group represents the collection. You can give it a different name by using the name = Group syntax

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