【发布时间】:2019-08-28 11:04:17
【问题描述】:
我需要将Linq函数的结果传递给ZipTwoBusinessObject类型的强类型变量,以便以后使用该对象的其他组件可以知道期望什么样的数据。
在我的例子中,这个组件是 asp:Repeater Web 窗体控件,我需要传入类型才能拥有强类型的转发器控件,但这是更普遍的问题。
我正在使用最新的 Visual Studio 2019。
Public Class ZipTwoBusinessObject
Public Property Name As String
Public Property Value1 As Decimal
Public Property Value2 As Decimal
End Class
Dim ZipTwo As List(Of ZipTwoBusinessObject) = Test1.Zip(Test2,
Function(ccc, ddd) New With {
.Name = ccc.Name,
.Value1 = ccc.Value,
.Value2 = ddd.Value
}).ToList
Linq 表达式返回错误:BC30311 'List(Of anonymous type: ...)' 类型的值无法转换为 'List(Of ZipTwoBusinessObject)'。
更新:
我可能会遍历 ZipTwo 的匿名元素并将其分配给 ZipTwoBusinessObject 的列表。但是使用 Linq Zip 方法是没有意义的,因为我可能会在同一个循环中压缩这两个对象。然而,这将是一个部分解决方案,因为使用Join 而不是Zip 并不容易。是的,我确实在其他地方使用了Join。
【问题讨论】: