我是Linq noobie,也许有人可以指出我正确的方向。这里有什么问题?这些匿名类型似乎具有相同的签名。
'*** 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 的建议代码(使用 {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
它应该是一个空列表。