0

I Would like to build the dynamic Linq to Sql query for inner join clause where inner join will include multiple dynamic columns for joining.

Below is the query at compile time which i need to acheive dynamically:

var source = lParent.GroupJoin(lChild,
    p => new{ p.PID,p.CategoryId (These are dynamic columns)}
    c => new{ c.PID,c.CategoryId (These are dynamic columns)}
    (p, g) =>  new { Parent = p, Childs= g })

Thank you.

Pieter Geerkens
  • 11,775
  • 2
  • 32
  • 52
  • What do you mean by "dynamically"? Will the user determine what columns to join on or do you want to re-use a query with different joins? Having dynamic join clauses seems odd. – D Stanley Jan 20 '16 at 16:43

1 Answers1

0

You can use the below query to have inner join. Use GroupJoin code from this link.

source.AsQueryable()
.GroupJoin(destination.AsQueryable(),
           outer.ToString(),
           inner.ToString(),
           "new (outer as sources, group as destinations)")
.SelectMany("destinations", "new(outer as sources, inner as destinations)");
Mantas Čekanauskas
  • 2,218
  • 6
  • 23
  • 43
Ashutosh
  • 53
  • 6