2009-05-06 83 views
1

說我創建了兩個臺的元組,像這樣:與匿名類型的LINQ在VB中工作,C#

Dim losSPResults As List(Of spGetDataResults) = m_dcDataClasses.spGetData.ToList 
    Dim loTupleKeys = From t In losSPResults Select t.key1, t.key2 

    '' Query on an existing dataset: 
    Dim loTupleExistingKeys = from t in m_losSPResults Select t.key3, t.key4 

現在我想,像這樣在這兩個列表進行設置操作:

Dim loTupleSetDifference = loTupleKeys.Except(loTupleExistingKeys) 

顯然,LINQ的不能在臺進行比較,如果它不知道集具有統一的定義,所以它會給我這個版本的錯誤:

Option Strict On disallows implicit conversions from 'System.Collections.Generic.IEnumerable(Of < anonymous type>)' to 'System.Collections.Generic.IEnumerable(Of < anonymous type>)'.

如何使用這些設置的聲明來使它們齧合? (對谷歌不多運氣)

[編輯] 仍然得到同樣的編譯錯誤:

'*** If we have initialized the list of tools, check to make sure it's up to date 
    Dim loTupleDatabaseTools = From tt In lottTorqueTools _ 
           Select StationIndex = tt.station_index, SlotNumber = tt.slot_number 
    Dim loTupleToolObjects = From tt In m_lottTorqueTools _ 
          Select StationIndex = tt.StationIndex, SlotNumber = tt.SlotNumber 

    Dim loTupleSetDifference = loTupleDatabaseTools.Except(loTupleToolObjects) 

錯誤是在這裏:

昏暗loTupleSetDifference = loTupleDatabaseTools.Except(loTupleToolObjects

Error 5 Option Strict On disallows implicit conversions from 'System.Collections.Generic.IEnumerable(Of < anonymous type>)' to 'System.Collections.Generic.IEnumerable(Of < anonymous type>)'.

回答

5

如果匿名類型在s中具有相同類型的屬性名稱相同ame命令,它們應該是相同的類型(並且因此是兼容的)。

編輯:基於評論和更新的問題,我懷疑你缺少的是能夠命名匿名類型的屬性。更改此:

Dim loTupleExistingKeys = from t in m_losSPResults Select t.key3, t.key4 

到這一點:

Dim loTupleExistingKeys = from t in m_losSPResults Select key1=t.key3, key2=t.key4 

只要類型是正確的,你可以接着是好的,沒有更多的工作。

+0

啊。我編輯了上面列的名稱。那肯定是問題 - 名稱不同?我該如何解決這個問題? – Daniel 2009-05-06 14:15:00