Thursday, 12 September 2013

Combine and sort 2 tables

Combine and sort 2 tables

I have 2 DataTables (in a DataSet)
Table 1:
ID|ident |Pos
------------------
0 | id425 | 0
1 | id123 | 3
Table 2:
ID|ident |default|Pos
---------------------------
0 | id1 | 6 |2
1 | id180 | 6 |1
Now i want to do a sort with LINQ that produces the following output:
Result
ident|Pos
-------------
id425|0
id180|1
id1 |2
id123|3
Now im struggeling around with LINQ to achieve this with one linq query. I
am new to LINQ so i hope somone has a hint for me. My problem is how to
sort the two tables and combine the result. My code so far is :
var query =
from t1 in dataSet.Tables[tableOne].AsEnumerable()
from t2 in dataSet.Tables[tableTwo].AsEnumerable()
orderby t1[Pos]
orderby t2[Pos]
select new {t1,t2};
but that doesn't work.

No comments:

Post a Comment