假设我创建了两组元组:

    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

现在我想对这两个列表执行set操作,如下所示:

    Dim loTupleSetDifference = loTupleKeys.Except(loTupleExistingKeys)

显然,如果Linq不知道这些集合具有统一的定义,那么它就不能对集合执行比较,所以它会给我这个构建错误:

  

Option Strict On禁止隐含   来自的转换   “System.Collections.Generic.IEnumerable(中   LT <!>;匿名类型<!> gt;)'到   “System.Collections.Generic.IEnumerable(中   LT <!>;匿名类型<!> gt;)'。

如何处理这些集合的声明以使它们成为网格? (谷歌运气不太好)

[编辑] 仍然得到相同的编译错误:

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

错误在这里:

Dim loTupleSetDifference = loTupleDatabaseTools.Except( loTupleToolObjects

  

错误5选项严格禁止   来自的隐式转换   “System.Collections.Generic.IEnumerable(中   LT <!>;匿名类型<!> gt;)'到   “System.Collections.Generic.IEnumerable(中   LT <!>;匿名类型<!> gt;)'。

有帮助吗?

解决方案

如果匿名类型具有相同类型的相同属性名称,则它们应该是相同的类型(因此兼容)。

编辑:根据评论和更新的问题,我怀疑你缺少的是能够以匿名类型命名属性。改变这个:

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

只要类型合适,你就可以没有更多的工作了。

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top