0

我正在寻找任何 LINQ 语法来获得我的数据库频率范围的结果。

SimpleSet 包含一个频率集数组。在每个频率集中,它可以是多个频率。如果一个频率与最小值和最大值 (1000 < 2000) 匹配,则它可以保留在结果列表中。

当前代码:

    Dim ret As New ObservableCollection(Of fSimpleItemSet)'the result

    Dim FreqMin As Double = 1000
    Dim FreqMax As Double = 2000
    Dim retTmp As New ObservableCollection(Of fSimpleItemSet)' fSimpleSet is the data collection
    retTmp = (From fSimple As fSimpleItemSet In Data Select fSimple) 'Get ALL items

    For Each fSimple As fSimpleItemSet In retTmp
        If fSimple.fFrequencySet IsNot Nothing Then
            For Each fFrequency As fFrequencySet In fSimple.fFrequencySet
                If fFrequency.Frequency > FreqMin And fFrequency.Frequency < FreqMax Then
                    ret.Add(fSimple)
                    Exit For
                End If
            Next
        End If
    Next

数据库结构

4

1 回答 1

1

您可以使用Any方法查找元素,其中至少有一个孩子通过指定条件:

Dim query = retTmp.Where(Function(fSimple) Not fSimple.fFrequencySet Is Nothing)
                  .Where(Function(fSimple) fSimple.fFrequencySet.Any(Function(fFrequency) fFrequency.Frequency > FreqMin And fFrequency.Frequency < FreqMax))

Dim retTmp As New ObservableCollection(Of fSimpleItemSet)(query)

或一Where通电话:

Dim query = retTmp.Where(Function(fSimple) Not fSimple.fFrequencySet Is Nothing AndAlso fSimple.fFrequencySet.Any(Function(fFrequency) fFrequency.Frequency > FreqMin And fFrequency.Frequency < FreqMax))
于 2013-04-03T12:10:52.760 回答