1

We are getting the result of dynamic GroupJoin query as IQueryable and we have to perform Union or concat on IQueryable. Below is the code which calls dynamic groupjoin function which return result as IQueryable and we are using the link How do I do a left outer join with Dynamic Linq? to get IQueryable result returned by GroupJoin

IQueryable leftOuterJoin= destination.AsQueryable().GroupJoin(source.AsQueryable(), "new(outer.SecurityID as SecurityID,outer.CUSIP as CUSIP)", "new(inner.SecurityID as SecurityID,inner.CUSIP as CUSIP)", "new (outer as source, group as destination )");

and

var rightOuterJoin= source.AsQueryable().GroupJoin(destination, "new(outer.SecurityID as SecurityID,outer.CUSIP as CUSIP)", "new(inner.SecurityID as SecurityID,inner.CUSIP as CUSIP)", "new (outer as source, group as destination )");

We need to perform something like below

var fullOuterJoin = leftOuterJoin.Union(rightOuterJoin);

help will be appreciated.

michal.jakubeczy
  • 8,221
  • 1
  • 59
  • 63
Ashutosh
  • 53
  • 6

1 Answers1

2

The Dynamic Linq already has defined a Union extension method for IQueryable, which looks like this

public static IQueryable Union(this IQueryable source, IQueryable other)
{
    if (source == null) throw new ArgumentNullException("source");
    return source.Provider.CreateQuery(
        Expression.Call(
            typeof(Queryable), "Union",
            new Type[] { source.ElementType },
            source.Expression, other.Expression));
}

so

var fullOuterJoin = leftOuterJoin.Union(rightOuterJoin);

should really compile and work.

If you need Concat, then add a similar method to the above, like this (basically replacing the word Union with Concat)

public static IQueryable Concat(this IQueryable source, IQueryable other)
{
    if (source == null) throw new ArgumentNullException("source");
    return source.Provider.CreateQuery(
        Expression.Call(
            typeof(Queryable), "Concat",
            new Type[] { source.ElementType },
            source.Expression, other.Expression));
}
Ivan Stoev
  • 195,425
  • 15
  • 312
  • 343