Linq 如何转换作为IQUERYABLE返回的动态GroupJoin结果以执行Union或Concat操作?
我们得到的动态GroupJoin查询结果是IQueryable,我们必须在IQueryable上执行Union或concat。 下面是调用动态groupjoin函数的代码,该函数将结果返回为IQueryable,我们使用该链接获取groupjoin返回的IQueryable结果Linq 如何转换作为IQUERYABLE返回的动态GroupJoin结果以执行Union或Concat操作?,linq,Linq,我们得到的动态GroupJoin查询结果是IQueryable,我们必须在IQueryable上执行Union或concat。 下面是调用动态groupjoin函数的代码,该函数将结果返回为IQueryable,我们使用该链接获取groupjoin返回的IQueryable结果 IQueryable leftOuterJoin=destination.AsQueryable().GroupJoin(source.AsQueryable(),“新建(outer.SecurityID作为Securi
IQueryable leftOuterJoin=destination.AsQueryable().GroupJoin(source.AsQueryable(),“新建(outer.SecurityID作为SecurityID,outer.CUSIP作为CUSIP)”,“新建(inner.SecurityID作为SecurityID,inner.CUSIP作为CUSIP)”,
“新建(外部作为源,组作为目标)”代码>
及
var righouterjoin=source.AsQueryable().GroupJoin(目标,“新建(outer.SecurityID作为SecurityID,outer.CUSIP作为CUSIP)”,
“新建(inner.SecurityID作为SecurityID,inner.CUSIP作为CUSIP)”,
“新建(外部作为源,组作为目标)”代码>
我们需要执行如下操作
var fullOuterJoin=leftOuterJoin.Union(righouterjoin)代码>
非常感谢您的帮助。动态Linq已经为IQueryable
定义了一个Union
扩展方法,如下所示
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));
}
所以
应该真正编译和工作
如果您需要Concat
,则向上述方法添加类似的方法,如下所示(基本上将Union
替换为Concat
)
var fullOuterJoin = leftOuterJoin.Union(rightOuterJoin);
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));
}