2013-02-08 175 views
0

我使用以下LINQ查詢從數據表中加入在LINQ查詢

var callBetweenNodesDetail = from r in dtRowCallBetweenNodes.AsEnumerable() 
             where ((r.Field<string>("F1") == VerSelected1) && (r.Field<string>("F2") == VerSelected2)) 
             select r; 

現在我想加入一個包含兩個字段的另一個數據表dtRowFile獲取數據「名稱」和「F2」,其中場「F2」是與DataTable中dtRowCallBetweenNodes 「F10」 匹配ResultSet中得到 「名」

+0

可能,這將幫助你 [Linq查詢聯接] [1] [1]:http://stackoverflow.com/questions/4813968/linq-query-joins – Prashant16 2013-02-08 11:24:00

回答

1

這會幫助:

var ret = from p in Table1.AsEnumerable() 
     join q in Table2.AsEnumerable() on p.Field<int>("ID") equals q.Field<int>("ID") into UP 
     from q in UP.DefaultIfEmpty() 
     select new 
     { 
      ID = p.Field<int>("ID"), 
      Type = p.Field<string>("Type"), 
      Part = q.Field<int>("Part"), 
      Quantity = q.Field<int>("Quantity") 
     }; 
0
var rowFileNames = from r1 in dtRowCallBetweenNodes.AsEnumerable() 
        join r2 in dtRowFile.AsEnumerable() 
        on  r1.Field<string>("F10") equals r2.Field<string>("F2") 
        where r1.Field<string>("F1") == VerSelected1 
        &&  r1.Field<string>("F2") == VerSelected2 
        select r2.Field<string>("Name"); 

Cross-Table Queries (LINQ to DataSet)