【问题标题】:Filter From the Two Data Table using linq使用 linq 从两个数据表中过滤
【发布时间】:2015-02-28 14:06:30
【问题描述】:

有两个名为 dtSource 和 dtDest 的数据表。必须从这两个数据表中筛选出第一列(PRIMARY)中的所有值都不匹配的行。

这就是我所做的:

var valueMismatchInBoth = from c in dtSource.AsEnumerable() 
                          where (from o in dtDest.AsEnumerable() 
                                 select o["PRIMARY"]).Contains(c["PRIMARY"].ToString()) 
                          select c;

【问题讨论】:

  • 请分享你到目前为止所做的事情。
  • var valueMismatchInBoth = from c in dtSource.AsEnumerable() where (from o in dtDest.AsEnumerable() select o["PRIMARY"]).Contains(c["PRIMARY"].ToString() ) 选择 c;

标签: c# linq


【解决方案1】:

希望这段代码有帮助

var valuematchInBoth = from c in dtSource.AsEnumerable()
                          join o in dtDest.AsEnumerable()
                          on o["PRIMARY"] equals c["PRIMARY"]
                          select c;

var valueMismatchInBoth = dtSource.Except(valuematchInBoth);

另一种解决方案是

var valueMismatchInBoth = from c in dtSource.AsEnumerable()
                          from o in dtDest.AsEnumerable()
                          where o["PRIMARY"] != c["PRIMARY"]
                          select c;

【讨论】:

猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2015-04-19
  • 1970-01-01
  • 1970-01-01
  • 2013-10-27
相关资源
最近更新 更多