我是Linq的初学者,希望有人能指点我正确的方向。这里有什么问题?这些匿名类型似乎具有相同的签名。
'*** Get all of the new list items'
Dim dsNewFiles = From l1 In list1 _
Where Not (From l2 In list2 _
Select l2.id, l2.timestamp).Contains(New With {l1.id, l1.timestamp})
我希望能够在上述代码中进行高亮显示,但是我收到了编译错误:
Value of type '<anonymous type> (line n)' cannot be converted to '<anonymous type> (line n)'.
在".Contains(New With{l1.id, l1.timestamp})"中,我认为它认为匿名类型在某些方面是不同的,但是id和timestamp列在两个列表中都是相同的。它们也按照相同的顺序排列。除此之外,还有什么可能不同呢?
[编辑 2009年7月10日16:28 EST]
我尝试了用户Meta-Knight提供的代码(New With {Key l1.id, l1.timestamp}),它修复了编译错误。然而,当我使用List1和List2运行代码时,如下所示:
List1 List2
id timestamp id timestamp
-- ---------- -- ----------
01 2009-07-10 00:00:00 01 2009-07-10 00:00:00
结果是:
dsNewFiles
id timestamp
-- ----------
01 2009-07-10 00:00:00
它应该是一个空列表。