加入LINQ查询

时间:2013-02-08 11:17:03

标签: c# linq

我正在使用以下LINQ查询从数据表中获取数据

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

现在我想加入另一个数据表dtRowFile,它包含两个字段“Name”和“F2”,其中字段“F2”与数据表dtRowCallBetweenNodes中的“F10”匹配,以获得resultset中的“Name”

2 个答案:

答案 0 :(得分: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")
      };

答案 1 :(得分: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)