Ejemplo n.º 1
0
        protected override Expression VisitShapedQueryExpression(ShapedQueryExpression shapedQueryExpression)
        {
            var shaperBody = InjectEntityMaterializer(shapedQueryExpression.ShaperExpression);

            var selectExpression = (SelectExpression)shapedQueryExpression.QueryExpression;

            shaperBody = new RelationalProjectionBindingRemovingExpressionVisitor(selectExpression).Visit(shaperBody);

            shaperBody = new IncludeCompilingExpressionVisitor(TrackQueryResults).Visit(shaperBody);

            var shaperLambda = Expression.Lambda(
                shaperBody,
                QueryCompilationContext2.QueryContextParameter,
                RelationalProjectionBindingRemovingExpressionVisitor.DataReaderParameter);

            if (Async)
            {
                return(Expression.New(
                           typeof(AsyncQueryingEnumerable <>).MakeGenericType(shaperLambda.ReturnType.GetGenericArguments().Single()).GetConstructors()[0],
                           Expression.Convert(QueryCompilationContext2.QueryContextParameter, typeof(RelationalQueryContext)),
                           Expression.Constant(_querySqlGeneratorFactory.Create()),
                           Expression.Constant(selectExpression),
                           Expression.Constant(shaperLambda.Compile())));
            }

            return(Expression.New(
                       typeof(QueryingEnumerable <>).MakeGenericType(shaperLambda.ReturnType).GetConstructors()[0],
                       Expression.Convert(QueryCompilationContext2.QueryContextParameter, typeof(RelationalQueryContext)),
                       Expression.Constant(_querySqlGeneratorFactory.Create()),
                       Expression.Constant(selectExpression),
                       Expression.Constant(shaperLambda.Compile())));
        }
Ejemplo n.º 2
0
        protected override Expression VisitShapedQueryExpression(ShapedQueryExpression shapedQueryExpression)
        {
            var shaperBody = InjectEntityMaterializer(shapedQueryExpression.ShaperExpression);

            var selectExpression = (SelectExpression)shapedQueryExpression.QueryExpression;

            shaperBody = new RelationalProjectionBindingRemovingExpressionVisitor(selectExpression).Visit(shaperBody);
            shaperBody = new IncludeCompilingExpressionVisitor(TrackQueryResults).Visit(shaperBody);
            var indexMapParameter = Expression.Parameter(typeof(int[]), "indexMap");

            if (selectExpression.IsNonComposedFromSql())
            {
                shaperBody = new IndexMapInjectingExpressionVisitor(indexMapParameter).Visit(shaperBody);
            }

            var shaperLambda = Expression.Lambda(
                shaperBody,
                QueryCompilationContext.QueryContextParameter,
                RelationalProjectionBindingRemovingExpressionVisitor.DataReaderParameter,
                indexMapParameter,
                _resultCoordinatorParameter);

            return(Expression.New(
                       (Async
                    ? typeof(AsyncQueryingEnumerable <>)
                    : typeof(QueryingEnumerable <>)).MakeGenericType(shaperLambda.ReturnType).GetConstructors()[0],
                       Expression.Convert(QueryCompilationContext.QueryContextParameter, typeof(RelationalQueryContext)),
                       Expression.Constant(_querySqlGeneratorFactory),
                       Expression.Constant(_sqlExpressionFactory),
                       Expression.Constant(_parameterNameGeneratorFactory),
                       Expression.Constant(selectExpression),
                       Expression.Constant(shaperLambda.Compile()),
                       Expression.Constant(_contextType),
                       Expression.Constant(_logger)));
        }