internal static Expression Parameterize(TableAlias outerAlias, Expression expr) { OuterParameterizer op = new OuterParameterizer(); op.outerAlias = outerAlias; return(op.Visit(expr)); }
internal static Expression Parameterize(TableAlias outerAlias, Expression expr, int parameterCounter) { OuterParameterizer op = new OuterParameterizer(); op.outerAlias = outerAlias; op.parameterCounter = parameterCounter; return op.Visit(expr); }
private Expression ExecuteProjection(ProjectionExpression projection, bool okayToDefer, bool isTopLevel) { // parameterize query projection = (ProjectionExpression)this.Parameterize(projection); if (this.scope != null) { // also convert references to outer alias to named values! these become SQL parameters too projection = (ProjectionExpression)OuterParameterizer.Parameterize(this.scope.Alias, projection); } string commandText = this.linguist.Format(projection.Select); ReadOnlyCollection <NamedValueExpression> namedValues = NamedValueGatherer.Gather(projection.Select); QueryCommand command = new QueryCommand(commandText, namedValues.Select(v => new QueryParameter(v.Name, v.Type, v.QueryType))); Expression[] values = namedValues.Select(v => Expression.Convert(this.Visit(v.Value), typeof(object))).ToArray(); string methExecute = okayToDefer ? nameof(QueryExecutor.ExecuteDeferred) : nameof(QueryExecutor.Execute); var plan = Expression.Call(this.executor, methExecute, new Type[] { projection.Projector.Type }, Expression.Constant(command), Expression.NewArrayInit(typeof(object), values) ); return(plan); }
// end mike private Expression ExecuteProjection(ProjectionExpression projection, bool okayToDefer) { okayToDefer &= (receivingMember != null && policy.IsDeferLoaded(receivingMember)); // parameterize query projection = (ProjectionExpression)policy.Mapping.Language.Parameterize(projection); if (scope != null) { // also convert references to outer alias to named values! these become SQL parameters too projection = (ProjectionExpression)OuterParameterizer.Parameterize(scope.Alias, projection); } var saveScope = scope; ParameterExpression reader = Expression.Parameter(typeof(DbDataReader), "r" + nReaders++); scope = new Scope(scope, reader, projection.Source.Alias, projection.Source.Columns); LambdaExpression projector = Expression.Lambda(Visit(projection.Projector), reader); scope = saveScope; List <string> columnNames = ColumnNamedGatherer.Gather(projector.Body); //mike string commandText = policy.Mapping.Language.Format(projection.Source); var namedValues = NamedValueGatherer.Gather(projection.Source); var names = namedValues.Select(v => v.Name).ToArray(); Expression[] values = namedValues.Select(v => Expression.Convert( v.ParameterBindingAction != null ? v.ParameterBindingAction((ConstantExpression)v.Value) : Visit(v.Value), typeof(object))).ToArray(); string methExecute = okayToDefer ? "ExecuteDeferred" : "Execute"; if (okayToDefer) { } // call low-level execute directly on supplied DbQueryProvider Expression result = Expression.Call(provider, methExecute, new[] { projector.Body.Type }, Expression.New( typeof(QueryCommand <>).MakeGenericType(projector.Body.Type). GetConstructors()[0], Expression.Constant(commandText), Expression.Constant(names), projector, Expression.Constant(columnNames) ), Expression.NewArrayInit(typeof(object), values) ); if (projection.Aggregator != null) { // apply aggregator result = DbExpressionReplacer.Replace(projection.Aggregator.Body, projection.Aggregator.Parameters[0], result); } return(result); }
private Expression ExecuteProjection(ProjectionExpression projection, bool okayToDefer) { projection = (ProjectionExpression)Parameterize(projection); if (_scope != null) { projection = (ProjectionExpression)OuterParameterizer.Parameterize(_scope.Alias, projection); } return(BuildExecuteEnumerableCommand(projection, okayToDefer)); }
private Expression ExecuteProjection(ProjectionExpression projection, bool okayToDefer) { projection = (ProjectionExpression)this.Parameterize(projection); if (this.scope != null) { projection = (ProjectionExpression)OuterParameterizer.Parameterize(this.scope.Alias, projection); } string commandText = this.linguist.Format(projection.Select); ReadOnlyCollection <NamedValueExpression> onlys = NamedValueGatherer.Gather(projection.Select); QueryCommand command = new QueryCommand(commandText, from v in onlys select new QueryParameter(v.Name, v.Type, v.QueryType)); Expression[] values = (from v in onlys select Expression.Convert(this.Visit(v.Value), typeof(object))).ToArray <UnaryExpression>(); return(this.ExecuteProjection(projection, okayToDefer, command, values)); }
private Expression ExecuteProjection(DbProjectionExpression projection, bool okayToDefer, bool isTopLevel) { projection = this.Parameterize(projection) as DbProjectionExpression; if (this.scope != null) { projection = OuterParameterizer.Parameterize(this.scope.Alias, projection) as DbProjectionExpression; } var commandText = this.linguist.Format(projection.Select); var namedValues = DbNamedValueGatherer.Gather(projection.Select); var command = new QueryCommand(commandText, namedValues.Select(v => new QueryParameter(v.Name, v.Type, v.QueryType))); var values = namedValues.Select(v => Expression.Convert(this.Visit(v.Value), typeof(object))).ToArray() as Expression[]; return(this.ExecuteProjection(projection, okayToDefer, command, values, isTopLevel)); }
private Expression ExecuteProjection(ProjectionExpression projection, bool okayToDefer) { projection = (ProjectionExpression)this.Parameterize(projection); if (this.scope != null) { // also convert references to outer alias to named values! these become SQL parameters too projection = (ProjectionExpression)OuterParameterizer.Parameterize(this.scope.Alias, projection); } string commandText = this.dbContext.BuildSql(projection.Select); ReadOnlyCollection <NamedValueExpression> namedValues = NamedValueGatherer.Gather(projection.Select); Expression[] values = namedValues.Select(v => Expression.Convert(this.Visit(v.Value), typeof(object))).ToArray(); return(this.ExecuteProjection(projection, okayToDefer, commandText, namedValues.Select(v => new NamedParameter(v.Name, v.Type, v.SqlType)).ToArray(), values)); }
private Expression ExecuteProjection(DbProjectionExpression projection, bool okayToDefer) { // parameterize query projection = (DbProjectionExpression)this.Parameterize(projection); if (this.scope != null) { // also convert references to outer alias to named values! these become SQL parameters too projection = (DbProjectionExpression)OuterParameterizer.Parameterize(this.scope.Alias, projection); } string commandText = this.mapping.Language.Format(projection.Select); ReadOnlyCollection <DbNamedValueExpression> namedValues = NamedValueGatherer.Gather(projection.Select); QueryCommand command = new QueryCommand(commandText, namedValues.Select(v => new QueryParameter(v.Name, v.Type, v.DbType)), null); Expression[] values = namedValues.Select(v => Expression.Convert(this.Visit(v.Value), typeof(object))).ToArray(); return(this.ExecuteProjection(projection, okayToDefer, command, values)); }
private Expression ExecuteProjection(ProjectionExpression projection, bool okayToDefer) { // parameterize query projection = (ProjectionExpression)Parameterize(projection); if (scope != null) { // also convert references to outer alias to named values! these become SQL parameters too projection = (ProjectionExpression)OuterParameterizer.Parameterize(scope.Alias, projection); } string commandText = linguist.Format(projection.Select); ReadOnlyCollection <NamedValueExpression> namedValues = NamedValueGatherer.Gather(projection.Select); var command = new QueryCommand(commandText, namedValues.Select(v => new QueryParameter(v.Name, v.Type, v.QueryType))); Expression[] values = namedValues.Select(v => Expression.Convert(Visit(v.Value), typeof(object))).ToArray(); return(ExecuteProjection(projection, okayToDefer, command, values)); }