Linq, VB - Anonymous type cannot be converted to anonymous type

I'm Linq noobie, maybe someone can point me in the right direction. What is wrong here? These anonymous types seem to have the same signature.

          '*** 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})

I want in the above code there is some way to highlight, but I get a compilation error:

Value of type '<anonymous type> (line n)' cannot be converted to '<anonymous type> (line n)'.

under ".Contains ( New from {l1.id, l1.timestamp} )"

I suppose he thinks the anonymous types are somewhat different, but the id and timestamp columns are the same in any list. They are also in the same order. What else could be between the two?

[Edit 7/10/2009 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

.

+3
2

:

New With {Key l1.id, Key l1.timestamp}

, .

Edit:

, , , .

Dim dsNewFiles = From l1 In list1 _
                           Where Not (From l2 In list2 _
                                      Select l2.ID, l2.TimeStamp).Contains(New With {Key l1.ID, Key l1.TimeStamp})

- :

Dim dsNewFiles = list1.Except(list2)

, Equals GetHashCode IEquatable (Of T). MSDN ().

Timespan , IEqualityComparer (Of T) .

+1

, . , , :

Class A 
BeginClass 
    Begin ID as Int Begin ... End 
    Stuff as String Begin ... End 
EndClass

Class B 
BeginClass 
    Begin Stuff as String Begin ... End 
    ID as Int Begin ... End 
EndClass

From a In someListofAs
Where Not (From b In someListofBs Select b).Contains(a)

, .

, LINQ , - . .

:

From l1 In list1 _
Where Not (From l2 In list2 _
    Select New With { ID = l2.id, Timestamp = l2.timestamp}).Contains(
        New With { ID = l1.id, Timestamp = l1.timestamp})
+1

Source: https://habr.com/ru/post/1712218/


All Articles