Linq to full outer连接数据集中的多个表

时间:2013-02-21 09:24:49

标签: c# linq

我的数据集中有3个表

表0,1,2分别具有id1,id2,id3列

我如何全外加入?

我在堆栈溢出中看到了很多问题,但它们只处理了2个表。我怎么能得到这个wen我有超过2个表

2 个答案:

答案 0 :(得分:1)

像这样你可以尝试

var data= (from t1 in db.table1
           join t2 in db.table2 on t1.ID equals t2.ID into t1t2
           from x in t1t2.DefaultIfEmpty()
           join t3 in db.table3 on t1.ID equals t3.ID into t1t3
           from y in t1t3.DefaultIfEmpty()
           select new { t1.id,  x.id,  y.id})

答案 1 :(得分:0)

 var rowData =
                        from row1 in dsResults.Tables[0].AsEnumerable()
                        join row2 in dsResults.Tables[1].AsEnumerable()
                            on row1.Field<decimal>("RecordId") equals row2.Field<decimal>("RecordId2")
                        join row3 in dsResults.Tables[2].AsEnumerable()
                            on row1.Field<decimal>("RecordId") equals row3.Field<decimal>("RecordId3")
                        select row1.ItemArray.Concat(row2.ItemArray).Concat(row3.ItemArray).ToArray();