【问题标题】:LINQ store result of join in a DataTableLINQ 将连接结果存储在 DataTable 中
【发布时间】:2013-01-30 13:16:39
【问题描述】:

在 linq 中有没有办法连接两个 DataTable 并将结果存储在另一个 DataTable 中?我的意思是 DataTable 不是组连接创建的层次结构。

这是我到目前为止获得的组加入代码。哪个有效,但我不明白如何处理结果。

var temp = from t1 in table1
           join t2 in table2
           on t1.Field<string>("a")
           equals t2.Field<string>("b") into t
           select t;

另外,如何使用由组加入创建的分层形式?

【问题讨论】:

标签: .net linq join datatable


【解决方案1】:

该 LINQ 查询应该为您提供 DataRow 对象的集合,对吗?您可以尝试using this approach on SO 将行转换为新表。

【讨论】:

  • 类型为System.Collections.Generic.IEnumerable&lt;System.Collections.Generic.IEnumerable&lt;System.Data.DataRow&gt;&gt; {System.Linq.Enumerable.GroupJoinIterator&lt;System.Data.DataRow,System.Data.DataRow,string,System.Collections.Generic.IEnumerable&lt;System.Data.DataRow&gt;&gt;}
  • 我不确定为什么它可以从该查询中进行双重枚举,这就是问题所在。您可以尝试通过在最后执行 t.SelectMany(i => i) 来解决这个问题,看看是否可以解决问题。 SelectMany 应该展平结果集。不确定这是否可行。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 2022-01-19
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-07-07
相关资源
最近更新 更多