LINQ直接投射错误

时间:2012-09-13 03:44:10

标签: vb.net linq casting

我使用两个表(A& B)来推导B中不存在的项目列表。

Dim results1 = From table1 In dt2 Where Not (From table2 In dt1 Where DirectCast(table2(0), String) = DirectCast(table1(0), String)).Any() Select DirectCast(table1(0), String)  

但我收到错误

Unable to cast object of type 'System.Double' to type 'System.String'.  

我需要进行转换?

2 个答案:

答案 0 :(得分:2)

此处不要使用“DirectCast” - 使用“table2(0).ToString()”或“CType”。

答案 1 :(得分:1)

如果您喜欢LINQ,为什么不考虑实体框架。它将您的表转换为强类型类,并将您的字段作为类的属性。使用LINQ时添加一些真正的简单性。

相关问题