开发者

Returning subset of dictionary with a complex type as a key with Linq

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 ra开发者_如何学CtesWithDuplicates = 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


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
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜