我需要查询一个数组。我试过使用LINQ但没有成功。
这是保险的简化结构
Public Class Insurance
Public _typ As String
Public _numb As Number()
Public _indi As Indicator()
End Class
Public Class Number
Sub New(ByVal n As String, ByVal i As String)
Me._ntype = n
Me._value = i
End Sub
Public _ntype As String
Public _value As String
End Class
Public Class Indicator
Sub New(ByVal it As String, ByVal ind As String)
Me._itype = it
Me._ind = ind
End Sub
Public _itype As String
Public _ind As String
End Class
这里我构建了一个小例子来解释保险数组的外观。实际上有一个服务人员向我提供阵列。
Dim insarray(4) As Insurance
Dim insa As New Insurance
insa._typ = "SJUKVARD"
insa._indi = New Indicator() {New Indicator("ST", "G"), New Indicator("TAX", "P"), New Indicator("PT", "6")}
insa._numb = New Number() {New Number("PIN", "1000"), New Number("AGN", "A0001")}
insarray(0) = insa
Dim insa2 As New Insurance
insa2._typ = "SJUKVARD"
insa2._indi = New Indicator() {New Indicator("ST", "G"), New Indicator("TAX", "P")}
insa2._numb = New Number() {New Number("PIN", "2000"), New Number("AGN", "A0002")}
insarray(1) = insa2
Dim insa3 As New Insurance
insa3._typ = "SJUKVARD"
insa3._indi = New Indicator() {New Indicator("ST", "G"), New Indicator("KAL", "T")}
insa3._numb = New Number() {New Number("PIN", "3000"), New Number("AGN", "A0003")}
insarray(2) = insa3
Dim insa4 As New Insurance
insa4._typ = "SJUKVARD"
insa4._indi = New Indicator() {New Indicator("ST", "G"), New Indicator("TAX", "P")}
insa4._numb = New Number() {New Number("PIN", "4000")}
insarray(3) = insa4
Dim insa5 As New Insurance
insa5._typ = "SJUK"
insa5._indi = New Indicator() {New Indicator("ST", "F"), New Indicator("TAX", "P")}
insa5._numb = New Number() {New Number("PIN", "5000"), New Number("AGN", "A0005")}
insarray(4) = insa5
Dim myIns As IEnumerable(Of Object)
myIns = ...(here should to LINQ question be)
在“myIns = ...”中我想构建一个LINQ查询
所以唯一的打击将是保险“insa2”。 LINQ可以实现吗?
希望有人可以帮助我:)。
答案 0 :(得分:0)
myIns = insarray.Where(Function(i) i._typ = "SJUKVARD" AndAlso _
i._numb.Any(Function (n) n._ntype = "AGN") AndAlso _
i._indi.All(function(ind) (ind._itype <> "PT") AndAlso _
(ind._itype = "TAX" OrElse ( ind._itype = "ST" AndAlso ind._ind="G"))))