/// <summary> /// Extracts the first inner SELECT from an IQueryable. Useful for building DataSelect expressions for Reporting /// </summary> /// <param name="qry">The qry.</param> /// <param name="propertyExpression">The property expression.</param> /// <param name="parameterName">Name of the parameter (forexample: 'p') from the qry to replace with the parameterExpression.</param> /// <returns></returns> public static Expression Extract( IQueryable qry, MemberExpression propertyExpression, string parameterName ) { MethodCallExpression methodCallExpression = qry.Expression as MethodCallExpression; Expression<Func<LambdaExpression>> executionLambda = Expression.Lambda<Func<LambdaExpression>>( methodCallExpression.Arguments[1] ); Expression extractedExpression = ( executionLambda.Compile().Invoke()).Body; var propertyParameterExpressionVisitor = new PropertyParameterExpressionVisitor( propertyExpression, parameterName ); return propertyParameterExpressionVisitor.Visit( extractedExpression ); }
/// <summary> /// Extracts the first inner SELECT from an IQueryable. Useful for building DataSelect expressions for Reporting /// </summary> /// <param name="qry">The qry.</param> /// <param name="propertyExpression">The property expression.</param> /// <param name="parameterName">Name of the parameter (forexample: 'p') from the qry to replace with the parameterExpression.</param> /// <returns></returns> public static Expression Extract(IQueryable qry, MemberExpression propertyExpression, string parameterName) { MethodCallExpression methodCallExpression = qry.Expression as MethodCallExpression; Expression <Func <LambdaExpression> > executionLambda = Expression.Lambda <Func <LambdaExpression> >(methodCallExpression.Arguments[1]); Expression extractedExpression = (executionLambda.Compile().Invoke()).Body; var propertyParameterExpressionVisitor = new PropertyParameterExpressionVisitor(propertyExpression, parameterName); return(propertyParameterExpressionVisitor.Visit(extractedExpression)); }