-5

我有以下内容,可以满足我想要的 2 个数据表中字段的相等性

var matched = from s in sendTable.AsEnumerable()
                     join r in recvTable.AsEnumerable() on
                     new { BUS = s.Field<int>("BUS"), 
                           IDENT = s.Field<int>("IDENT"), 
                           STATION = s.Field<int>("STATION"), 
                           REF1 = s.Field<string>("REF1"), 
                           REF2 = s.Field<string>("REF2"),
                           REF3 = s.Field<string>("REF3"),
                           REF4 = s.Field<string>("REF4"),
                           REF5 = s.Field<string>("REF5"),
                           REF6 = s.Field<string>("REF6"),
                           REF7 = s.Field<string>("REF7"),
                           REF8 = s.Field<string>("REF8") } equals
                      new { BUS = r.Field<int>("BUS"), 
                           IDENT = r.Field<int>("IDENT"), 
                           STATION = r.Field<int>("STATION"), 
                           REF1 = r.Field<string>("REF1"), 
                           REF2 = r.Field<string>("REF2"),
                           REF3 = r.Field<string>("REF3"),
                           REF4 = r.Field<string>("REF4"),
                           REF5 = r.Field<string>("REF5"),
                           REF6 = r.Field<string>("REF6"),
                           REF7 = r.Field<string>("REF7"),
                           REF8 = r.Field<string>("REF8") } 
                     select new { Send = s, Receive = r };

我现在想要的是不等式,我该如何使用除了?

4

1 回答 1

1

您可以Enumerable.Except在这些字段上使用:

var sendIdentityFields = from s in sendTable.AsEnumerable()
                         select new
                         {
                             BUS = s.Field<int>("BUS"),
                             IDENT = s.Field<int>("IDENT"),
                             STATION = s.Field<int>("STATION"),
                             REF1 = s.Field<string>("REF1"),
                             REF2 = s.Field<string>("REF2"),
                             REF3 = s.Field<string>("REF3"),
                             REF4 = s.Field<string>("REF4"),
                             REF5 = s.Field<string>("REF5"),
                             REF6 = s.Field<string>("REF6"),
                             REF7 = s.Field<string>("REF7"),
                             REF8 = s.Field<string>("REF8")
                         };
var receivedIdentityFields = from r in sendTable.AsEnumerable()
                         select new
                         {
                             BUS = r.Field<int>("BUS"),
                             IDENT = r.Field<int>("IDENT"),
                             STATION = r.Field<int>("STATION"),
                             REF1 = r.Field<string>("REF1"),
                             REF2 = r.Field<string>("REF2"),
                             REF3 = r.Field<string>("REF3"),
                             REF4 = r.Field<string>("REF4"),
                             REF5 = r.Field<string>("REF5"),
                             REF6 = r.Field<string>("REF6"),
                             REF7 = r.Field<string>("REF7"),
                             REF8 = r.Field<string>("REF8")
                         };
var sendButNotReceived = sendIdentityFields.Except(receivedIdentityFields);

当然,这只会选择带有这些字段的匿名类型,而不是DataRows. 如果您需要选择其中的DataRows一个,则sendTable需要将它们与此结果连接到相同的字段中。

于 2012-12-18T14:30:03.303 回答