Rajeev Kumar
Rajeev Kumar

Reputation: 4963

Join in LINQ Query

I am using Following LINQ query to fetch data from datatable

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

Now i wanna join another datatable dtRowFile that contains two fields "Name" and "F2" where field "F2" is to be matched with "F10" in datatable dtRowCallBetweenNodes to get "Name" in resultset

Upvotes: 0

Views: 120

Answers (2)

Tim Schmelter
Tim Schmelter

Reputation: 460278

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)

Upvotes: 0

Andrew Beal
Andrew Beal

Reputation: 427

Would this help:

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")
      };

Upvotes: 1

Related Questions