我有两个linq
查询:
Dim lnqPrüfendeartikel = (From row In dtKonf
Let ARTNR_HZ = row.Field(Of String)("ARTNR-HZ")
Let ENDARTNR = row.Field(Of String)("ARTNR")
Where ARTNR_HZ <> ""
Select ARTNR_HZ, ENDARTNR
Order By ARTNR_HZ).Distinct
Dim lnqPrüfendeartikel2 = (From row In dtKonf
Let ROHNR = row.Field(Of String)("ROHNR")
Let ENDARTNR = row.Field(Of String)("ARTNR")
Where ROHNR <> ""
Select ROHNR, ENDARTNR
Order By ROHNR).Distinct
我想将两个结果连接起来:
lnqPrüfendeartikel.Concat(lnqPrüfendeartikel2)
但我收到错误:
'System.Collections.Generic.IEnumerable(Of)'不能 转换为'System.Collections.Generic.IEnumerable(Of)'因为'(第177行)'不是从 '(第170行)','Out'泛型所要求的 'Interface IEnumerable(Of Out T)'中的参数'T'
对我来说,一切似乎都是对的:我在查询两个字段时都有,而且数据类型也一样。
那么错误是什么?
答案 0 :(得分:2)
您选择了匿名类型。属性名称源自LINQ查询的Let
- 子句中的名称。所以第一个有两个属性:
ARTNR_HZ As String
ENDARTNR As String
,第二个
ROHNR As String
ENDARTNR As String
您只能连接相同类型的序列。但是这些类型不同,因为它们的名称不同(请注意even the order matters)。因此,您可以使用相同的名称和类型创建具有相同属性的匿名类型:
Dim lnqPrüfendeartikel = (From row In dtKonf
Let ARTNR_HZ = row.Field(Of String)("ARTNR-HZ")
Let ENDARTNR = row.Field(Of String)("ARTNR")
Where ARTNR_HZ <> ""
Select x = New With { Key .HZ = ARTNR_HZ, Key .NR = ENDARTNR }
Order By x.HZ).Distinct()
Dim lnqPrüfendeartikel2 = (From row In dtKonf
Let ROHNR = row.Field(Of String)("ROHNR")
Let ENDARTNR = row.Field(Of String)("ARTNR")
Where ROHNR <> ""
Select ROHNR, ENDARTNR
Select x = New With { Key .HZ = ROHNR, Key .NR = ENDARTNR }
Order By x.HZ).Distinct()
现在你可以连接两个:
Dim both = lnqPrüfendeartikel.Concat(lnqPrüfendeartikel2)
另一个应用是将Let
- 变量的名称更改为在两个查询中都相同。