合并具有相同ID或名称的2个动态表数据

时间:2016-12-13 12:04:18

标签: c# asp.net

我有2个表,基于id

,数据为dt1和dt2
id column1 column2
1   abc

id column1 column2
1           def

我该怎样才能成为

id column1 column2
1     abc     def

我需要一个c#代码

1 个答案:

答案 0 :(得分:1)

答案取自:https://stackoverflow.com/a/2767742/2537148

var query = database.dt1// your starting point - table in the "from" statement
       .Join(database.dt2, // the source table of the inner join
          post => dt1.id,        // Select the primary key (the first part of the "on" clause in an sql "join" statement)
          meta => dt2.id,   // Select the foreign key (the second part of the "on" clause)
          (dt1, dt2) => new { Dt1= dt1, Dt2= dt2}); // selection