public ExpressionCacheKey(SqlProjectionExpression expression, LambdaExpression projector) : this() { this.expression = expression; this.projector = projector; this.hash = SqlExpressionHasher.Hash(expression, SqlExpressionComparerOptions.IgnoreConstantPlaceholders) ^ SqlExpressionHasher.Hash(projector); }
protected override Expression VisitProjection(SqlProjectionExpression projection) { var saveInProjection = this.inProjection; this.inProjection = true; base.VisitProjection(projection); this.inProjection = saveInProjection; return projection; }
protected static SqlProjectionExpression UpdateProjection(SqlProjectionExpression projectionExpression, SqlSelectExpression select, Expression projector, LambdaExpression aggregator) { if (select != projectionExpression.Select || projector != projectionExpression.Projector || aggregator != projectionExpression.Aggregator) { return new SqlProjectionExpression(select, projector, aggregator, projectionExpression.IsElementTableProjection, projectionExpression.SelectFirstType, projectionExpression.DefaultValueExpression, projectionExpression.IsDefaultIfEmpty); } return projectionExpression; }
protected static SqlProjectionExpression UpdateProjection(SqlProjectionExpression projectionExpression, SqlSelectExpression select, Expression projector, LambdaExpression aggregator) { if (select != projectionExpression.Select || projector != projectionExpression.Projector || aggregator != projectionExpression.Aggregator) { return(new SqlProjectionExpression(select, projector, aggregator, projectionExpression.IsElementTableProjection, projectionExpression.SelectFirstType, projectionExpression.DefaultValueExpression, projectionExpression.IsDefaultIfEmpty)); } return(projectionExpression); }
protected override Expression VisitProjection(SqlProjectionExpression projection) { if (hasAggregate) { return projection; } return base.VisitProjection(projection); }
protected override Expression VisitProjection(SqlProjectionExpression projection) { // Visit mapping in reverse order var projector = this.Visit(projection.Projector); var select = (SqlSelectExpression)this.Visit(projection.Select); return UpdateProjection(projection, select, projector, projection.Aggregator); }
protected override Expression VisitProjection(SqlProjectionExpression projection) { var previousProjection = this.currentProjection; this.currentProjection = projection; var retval = base.VisitProjection(projection); this.currentProjection = previousProjection; return retval; }
protected override Expression VisitProjection(SqlProjectionExpression projection) { SqlProjectionExpression current; if (!TryGetCurrent(projection, out current)) { return(projection); } result = result && (current.IsDefaultIfEmpty == projection.IsDefaultIfEmpty && current.IsElementTableProjection == projection.IsElementTableProjection && current.SelectFirstType == projection.SelectFirstType); if (!result) { return(projection); } currentObject = current.Aggregator; Visit(projection.Aggregator); if (!result) { return(projection); } currentObject = current.DefaultValueExpression; Visit(projection.DefaultValueExpression); if (!result) { return(projection); } currentObject = current.Projector; Visit(projection.Projector); if (!result) { return(projection); } currentObject = current.Select; Visit(projection.Select); if (!result) { return(projection); } return(projection); }
protected override Expression VisitProjection(SqlProjectionExpression projection) { var source = (SqlSelectExpression)this.Visit(projection.Select); var projector = this.Visit(projection.Projector); var aggregator = (LambdaExpression) this.Visit(projection.Aggregator); if (source != projection.Select || projector != projection.Projector || aggregator != projection.Aggregator) { return new SqlProjectionExpression(source, projector, aggregator, projection.IsElementTableProjection); } return projection; }
protected virtual Expression VisitProjection(SqlProjectionExpression projection) { var source = (SqlSelectExpression)Visit(projection.Select); var projector = Visit(projection.Projector); var defaulValueExpression = Visit(projection.DefaultValueExpression); var aggregator = (LambdaExpression)Visit(projection.Aggregator); if (source != projection.Select || projector != projection.Projector || defaulValueExpression != projection.DefaultValueExpression || aggregator != projection.Aggregator) { return(new SqlProjectionExpression(source, projector, aggregator, projection.IsElementTableProjection, projection.SelectFirstType, projection.DefaultValueExpression, projection.IsDefaultIfEmpty)); } return(projection); }
protected override Expression VisitProjection(SqlProjectionExpression projection) { projection = (SqlProjectionExpression)base.VisitProjection(projection); if (projection.Select.From is SqlSelectExpression) { var redundantQueries = RedundantSubqueryFinder.Find(projection.Select); if (redundantQueries != null) { projection = SubqueryRemover.Remove(projection, redundantQueries); } } return projection; }
protected override Expression VisitFunctionCall(SqlFunctionCallExpression functionCallExpression) { if (functionCallExpression.Function == SqlFunction.In) { if (functionCallExpression.Arguments[0].NodeType == ExpressionType.Constant && functionCallExpression.Arguments[1].NodeType == (ExpressionType)SqlExpressionType.Projection) { var projector = (SqlProjectionExpression)functionCallExpression.Arguments[1]; if (projector.Select.Where == null && projector.Select.Columns.Count == 1) { var newWhere = Expression.Equal(functionCallExpression.Arguments[0], projector.Select.Columns[0].Expression); var newSelect = projector.Select.ChangeWhere(newWhere); var newProjection = new SqlProjectionExpression(newSelect, projector, projector.Aggregator); return new SqlFunctionCallExpression(functionCallExpression.Type, SqlFunction.Exists, new Expression[] { newProjection }); } } } return base.VisitFunctionCall(functionCallExpression); }
private SqlNullComparisonCoalescer(SqlProjectionExpression rootProjection) { this.ignoreExpression = rootProjection.Projector; }
public SqlInsertIntoExpression ChangeSourceAndValueExpressions(SqlProjectionExpression source, IReadOnlyList <Expression> valueExpressions) { return(new SqlInsertIntoExpression(source, this.ColumnNames, this.ReturningAutoIncrementColumnNames, valueExpressions, this.WithExpression, this.RequiresIdentityInsert)); }
protected override Expression VisitProjection(SqlProjectionExpression expression) { SqlProjectionExpression current; if (!TryGetCurrent(expression, out current)) { return expression; } if (!(this.result &= current.IsElementTableProjection == expression.IsElementTableProjection)) { return expression; } if (!(this.result &= current.NodeType == expression.NodeType)) { return expression; } if (!(this.result &= current.Type == expression.Type)) { return expression; } this.currentObject = current.DefaultValue; this.Visit(expression.DefaultValue); if (!this.result) { return expression; } this.currentObject = current.Select; this.VisitSelect(expression.Select); if (!this.result) { return expression; } this.currentObject = current.Projector; this.Visit(expression.Projector); if (!this.result) { return expression; } this.currentObject = current.Aggregator; this.VisitLambda(expression.Aggregator); if (!this.result) { return expression; } this.currentObject = current; return expression; }
public static SqlProjectionExpression Remove(SqlProjectionExpression projection, params SqlSelectExpression[] selectsToRemove) { return Remove(projection, (IEnumerable<SqlSelectExpression>)selectsToRemove); }
protected override Expression VisitProjection(SqlProjectionExpression projectionExpression) { if (typeof(RelatedDataAccessObjects<>).IsAssignableFromIgnoreGenericParameters(projectionExpression.Type)) { var elementType = projectionExpression.Type.GetGenericArguments()[0]; var originalPlaceholderCount = 0; var currentPlaceholderCount = originalPlaceholderCount; var replacedExpressions = new List<Expression>(); projectionExpression = (SqlProjectionExpression)SqlOuterQueryReferencePlaceholderSubstitutor.Substitute(projectionExpression, ref currentPlaceholderCount, replacedExpressions); var values = replacedExpressions.Select(c => Expression.Convert(this.Visit(c), typeof(object))).ToList(); var where = projectionExpression.Select.Where; var typeDescriptor = this.dataAccessModel.TypeDescriptorProvider.GetTypeDescriptor(elementType); var columns = QueryBinder.GetColumnInfos(this.dataAccessModel.TypeDescriptorProvider, typeDescriptor.PersistedProperties); var columnExpression = (SqlColumnExpression)SqlExpressionFinder.FindFirst(where, c => c.NodeType == (ExpressionType)SqlExpressionType.Column); var match = columns.Single(d => d.ColumnName == columnExpression.Name); var reference = Expression.Call(Expression.Constant(this.dataAccessModel), MethodInfoFastRef.DataAccessModelGetReferenceByValuesMethod.MakeGenericMethod(match.ForeignType.Type), Expression.NewArrayInit(typeof(object), values)); var property = typeDescriptor.GetRelationshipInfos().Single(c => c.ReferencingProperty == match.RootProperty).TargetProperty; return Expression.Convert(Expression.Property(reference, property), this.dataAccessModel.GetConcreteTypeFromDefinitionType(property.PropertyType)); } else { var currentPlaceholderCount = 0; var replacedExpressions = new List<Expression>(); projectionExpression = (SqlProjectionExpression)SqlOuterQueryReferencePlaceholderSubstitutor.Substitute(projectionExpression, ref currentPlaceholderCount, replacedExpressions); var newColumnIndexes = projectionExpression.Select.Columns.Select((c, i) => new { c.Name, i }).ToDictionary(d => d.Name, d => d.i); var savedScope = this.scope; this.scope = new ProjectionBuilderScope(newColumnIndexes); var projectionProjector = Expression.Lambda(this.Visit(projectionExpression.Projector), objectProjector, dataReader, versionParameter, dynamicParameters, filterParameter); Expression rootKeys; if (this.scope.rootPrimaryKeys.Count > 0) { rootKeys = Expression.Quote(Expression.Lambda<Func<IDataReader, object[]>>(Expression.NewArrayInit(typeof(object), this.scope.rootPrimaryKeys), this.dataReader)); } else { rootKeys = Expression.Constant(null, typeof(Expression<Func<IDataReader, object[]>>)); } this.scope = savedScope; var values = replacedExpressions.Select(c => (Expression)Expression.Convert(Visit(c), typeof(object))).ToList(); var method = TypeUtils.GetMethod<SqlQueryProvider>(c => c.BuildExecution(default(SqlProjectionExpression), default(LambdaExpression), default(object[]), default(Expression<Func<IDataReader, object[]>>))); MethodInfo evaluate; if (projectionExpression.Type.GetSequenceElementType() == null) { evaluate = MethodInfoFastRef.ExecutionBuildResultEvaluateMethod.MakeGenericMethod(projectionExpression.Type); } else { evaluate = MethodInfoFastRef.ExecutionBuildResultEvaluateMethod.MakeGenericMethod(typeof(IEnumerable<>).MakeGenericType(projectionExpression.Type.GetSequenceElementType())); } return Expression.Call(Expression.Call(Expression.Property(this.objectProjector, "QueryProvider"), method, Expression.Constant(SqlAggregateProjectionNormalizer.Normalize(projectionExpression)), projectionProjector, Expression.NewArrayInit(typeof(object), values), rootKeys), evaluate); } }
protected virtual Expression VisitProjection(SqlProjectionExpression projection) { var source = (SqlSelectExpression)Visit(projection.Select); var projector = Visit(projection.Projector); var defaulValueExpression = Visit(projection.DefaultValueExpression); var aggregator = (LambdaExpression)Visit(projection.Aggregator); if (source != projection.Select || projector != projection.Projector || defaulValueExpression != projection.DefaultValueExpression || aggregator != projection.Aggregator) { return new SqlProjectionExpression(source, projector, aggregator, projection.IsElementTableProjection, projection.SelectFirstType, projection.DefaultValueExpression, projection.IsDefaultIfEmpty); } return projection; }
protected override Expression VisitProjection(SqlProjectionExpression projection) { return(base.VisitProjection(projection)); }
protected override Expression VisitProjection(SqlProjectionExpression projection) { var subQuery = Expression.Lambda(projection, this.objectProjector); var elementType = TypeHelper.GetElementType(subQuery.Body.Type); var boundExecuteSubQueryMethod = ExecuteSubQueryMethod.MakeGenericMethod(elementType); return Expression.Convert(Expression.Call(this.objectProjector, boundExecuteSubQueryMethod, Expression.Constant(subQuery), this.dataReader), projection.Type); }
public SqlInsertIntoExpression ChangeSourceAndValueExpressions(SqlProjectionExpression source, IReadOnlyList<Expression> valueExpressions) { return new SqlInsertIntoExpression(source, this.ColumnNames, this.ReturningAutoIncrementColumnNames, valueExpressions); }
public ProjectorExpressionCacheInfo(SqlProjectionExpression projectionExpression, SqlQueryFormatResult formatResult) : this() { this.projectionExpression = projectionExpression; this.formatResult = formatResult; }
public static SqlProjectionExpression Remove(SqlProjectionExpression projection, IEnumerable<SqlSelectExpression> selectsToRemove) { return (SqlProjectionExpression)new SubqueryRemover(selectsToRemove).Visit(projection); }
protected override Expression VisitProjection(SqlProjectionExpression expression) { this.hashCode ^= expression.IsElementTableProjection ? -751039749 : 0; return(base.VisitProjection(expression)); }
protected override Expression VisitProjection(SqlProjectionExpression expression) { this.hashCode ^= expression.IsElementTableProjection ? -751039749 : 0; return base.VisitProjection(expression); }
protected override Expression VisitProjection(SqlProjectionExpression projection) { var previousCurrentProjectShouldBeDefaultIfEmpty = this.currentProjectShouldBeDefaultIfEmpty; this.currentProjectShouldBeDefaultIfEmpty = projection.IsDefaultIfEmpty; var retval = this.Visit(projection.Select); this.currentProjectShouldBeDefaultIfEmpty = previousCurrentProjectShouldBeDefaultIfEmpty; return retval; }
protected override Expression VisitProjection(SqlProjectionExpression projection) { var source = (SqlSelectExpression) this.Visit(projection.Select); var oldInProjector = this.inProjector; this.inProjector = true; Expression projector; try { projector = this.Visit(projection.Projector); } finally { this.inProjector = oldInProjector; } var aggregator = (LambdaExpression) this.Visit(projection.Aggregator); if (source != projection.Select || projector != projection.Projector || aggregator != projection.Aggregator) { return new SqlProjectionExpression(source, projector, aggregator, projection.IsElementTableProjection, projection.SelectFirstType, projection.DefaultValueExpression, projection.IsDefaultIfEmpty); } return projection; }
protected override Expression VisitProjection(SqlProjectionExpression projection) { var retval = this.Visit(projection.Select); return retval; }
protected override Expression VisitProjection(SqlProjectionExpression projection) { var saveProjection = this.currentProjection; try { this.currentProjection = projection; return base.VisitProjection(projection); } finally { this.currentProjection = saveProjection; } }
protected virtual Expression VisitProjection(SqlProjectionExpression projection) { var source = (SqlSelectExpression)this.Visit(projection.Select); var projector = this.Visit(projection.Projector); var defaulValueExpression = this.Visit(projection.DefaultValue); var aggregator = (LambdaExpression)this.Visit(projection.Aggregator); var defaultValue = this.Visit(projection.DefaultValue); if (source != projection.Select || projector != projection.Projector || defaulValueExpression != projection.DefaultValue || aggregator != projection.Aggregator || defaultValue != projection.DefaultValue) { return new SqlProjectionExpression(projection.Type, source, projector, aggregator, projection.IsElementTableProjection, projection.DefaultValue); } return projection; }