【问题标题】:Finding duplicate values in row(s) in different tables using linq vb.net使用 linq vb.net 在不同表中的行中查找重复值
【发布时间】:2013-11-13 19:31:12
【问题描述】:

所以我有 2 个这样的数据表:

table1:    |mean1|mean2|   table2: |mean1|mean2|
           -------------           -------------
           |1.2  | 1.3 |           |2.2  | 1.3 |
           |2.0  | 2.0 | <=======> |2.0  | 2.0 |
           |1.0  | 2.3 |           |3.0  | 1.0 | 
           |1.4  | 2.7 |           |3.0  | 1.2 |
           |1.5  | 2.8 |           |2.7  | 1.3 |
           |2.2  | 1.1 | <=======> |2.2  | 1.1 |

我的目标是从 table2 中找到包含在 table1 中的值。必须写在VB.Net

在 table1 中查找重复项的代码仅如下所示:

Dim dupes = From row In table1.AsEnumerable()
            Group row By G = New With {.mean1= row.Field(Of Double)("mean1")}.mean1,
            New With {.mean2= row.Field(Of Double)("mean2")}.mean2 Into DupMean = Group
            Where DupMean.Count() > 1
            Select DupMean

如何将代码与 table2 结合起来?

【问题讨论】:

    标签: vb.net linq


    【解决方案1】:

    类似的东西

    Dim dupes = From row In table1.AsEnumerable()
                Join row2 In table2.AsEnumerable()
                On row("mean1") Equals row2("mean1") And row("mean2") Equals row2("mean2")
                Select New With {.RowInT1 = row, .RowEqualInT2 = row2}
    

    或者,包括每个表的内部副本:

    Dim dupes = From row In table1.AsEnumerable().Concat(table1.AsEnumerable()()
                Group row By G = New With {.mean1 = row("mean1"), .mean2 = row("mean2")}
                Into DupMean = Group
                Where DupMean.Count() > 1
                Select DupMean
    

    【讨论】:

    • 在我看来,Field(Of T) 方法在这里是不必要的。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-11-07
    • 1970-01-01
    • 2016-10-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多