Наследование: SqlBaseExpression, ISqlExposesAliases
Пример #1
0
        protected override Expression VisitJoin(SqlJoinExpression join)
        {
            SqlJoinExpression current;

            if (!TryGetCurrent(join, out current))
            {
                return(join);
            }

            result = result && (current.JoinType == join.JoinType);

            if (result)
            {
                currentObject = current.JoinCondition;
                Visit(join.JoinCondition);

                currentObject = current.Left;
                Visit(join.Left);

                currentObject = current.Right;
                Visit(join.Right);

                currentObject = current;
            }

            return(join);
        }
Пример #2
0
		protected override Expression VisitJoin(SqlJoinExpression join)
		{
			join = (SqlJoinExpression)base.VisitJoin(join);

			if (join.JoinType == SqlJoinType.Cross && this.currentWhere != null)
			{
				var declaredLeft = SqlDeclaredAliasGatherer.Gather(join.Left);
				var declaredRight = SqlDeclaredAliasGatherer.Gather(join.Right);
				var declared = new HashSet<string>(declaredLeft.Union(declaredRight));
				var exprs = this.currentWhere.Split(ExpressionType.And, ExpressionType.AndAlso);
				var good = exprs.Where(e => CanBeJoinCondition(e, declaredLeft, declaredRight, declared)).ToList();

				if (good.Count > 0 )
				{
					var condition = good.Join(ExpressionType.And);

					join = this.UpdateJoin(join, SqlJoinType.Inner, join.Left, join.Right, condition);

					var newWhere = exprs.Where(e => !good.Contains(e)).Join(ExpressionType.And);
					this.currentWhere = newWhere;
				}
			}

			return join;
		}
Пример #3
0
		protected SqlJoinExpression UpdateJoin(SqlJoinExpression join, SqlJoinType joinType, Expression left, Expression right, Expression condition)
		{
			if (joinType != join.JoinType || left != join.Left || right != join.Right || condition != join.JoinCondition)
			{
				return new SqlJoinExpression(join.Type, joinType, left, right, condition);
			}

			return join;
		}
Пример #4
0
        protected override Expression VisitJoin(SqlJoinExpression join)
        {
            if (this.hasAggregate)
            {
                return join;
            }

            return base.VisitJoin(join);
        }
Пример #5
0
        protected virtual Expression VisitJoin(SqlJoinExpression join)
        {
            var left      = this.Visit(join.Left);
            var right     = this.Visit(join.Right);
            var condition = this.Visit(join.JoinCondition);

            if (left != join.Left || right != join.Right || condition != join.JoinCondition)
            {
                return(new SqlJoinExpression(join.Type, join.JoinType, left, right, condition));
            }

            return(join);
        }
Пример #6
0
        protected override Expression VisitJoin(SqlJoinExpression join)
        {
            // Visit join in reverse order

            var condition = this.Visit(join.JoinCondition);
            var right = this.VisitSource(join.Right);
            var left = this.VisitSource(join.Left);

            if (left != join.Left || right != join.Right || condition != join.JoinCondition)
            {
                return new SqlJoinExpression(join.Type, join.JoinType, left, right, condition);
            }

            return join;
        }
Пример #7
0
		protected override Expression VisitJoin(SqlJoinExpression join)
		{
			this.Visit(join.Left);
			this.Visit(join.Right);
			
			if (this.inProjection)
			{
				var saveCanBeColumn = this.canBeColumn;

				this.canBeColumn = c => c is SqlColumnExpression;

				this.Visit(join.JoinCondition);

				this.canBeColumn = saveCanBeColumn;
			}

			return join;
		}
Пример #8
0
        protected override Expression VisitJoin(SqlJoinExpression join)
        {
            join = (SqlJoinExpression)base.VisitJoin(join);

            if (join.JoinType == SqlJoinType.CrossApply || join.JoinType == SqlJoinType.OuterApply)
            {
                if (join.Right is SqlTableExpression)
                {
                    return new SqlJoinExpression(join.Type, SqlJoinType.Cross, join.Left, join.Right, null);
                }
                else
                {
                    var select = join.Right as SqlSelectExpression;

                    if (select != null && select.Take == null && select.Skip == null && !SqlAggregateChecker.HasAggregates(select) && (select.GroupBy == null || select.GroupBy.Count == 0))
                    {
                        var selectWithoutWhere = select.ChangeWhere(null);
                        var referencedAliases = SqlReferencedAliasGatherer.Gather(selectWithoutWhere);
                        var declaredAliases = SqlDeclaredAliasGatherer.Gather(join.Left);

                        referencedAliases.IntersectWith(declaredAliases);

                        if (referencedAliases.Count == 0)
                        {
                            var where = select.Where;

                            select = selectWithoutWhere;

                            var pc = ColumnProjector.ProjectColumns(Nominator.Default, where, select.Columns, select.Alias, SqlDeclaredAliasGatherer.Gather(select.From));

                            select = select.ChangeColumns(pc.Columns);
                            where = pc.Projector;

                            var joinType = (where == null) ? SqlJoinType.Cross : (join.JoinType == SqlJoinType.CrossApply ? SqlJoinType.Inner : SqlJoinType.Left);

                            return new SqlJoinExpression(typeof(void), joinType, join.Left, select, where);
                        }
                    }
                }
            }

            return join;
        }
Пример #9
0
		protected override Expression VisitJoin(SqlJoinExpression join)
		{
			ignoreSet.Add(join.Left);
			ignoreSet.Add(join.Right);

			var left = this.Visit(join.Left);
			var right = this.Visit(join.Right);
			
			ignoreSet.Remove(join.Left);
			ignoreSet.Remove(join.Right);

			var condition = this.Visit(join.JoinCondition);

			if (left != join.Left || right != join.Right || condition != join.JoinCondition)
			{
				return new SqlJoinExpression(join.Type, join.JoinType, left, right, condition);
			}

			return join;
		}
Пример #10
0
 protected override Expression VisitJoin(SqlJoinExpression expression)
 {
     this.hashCode ^= expression.JoinType.GetHashCode();
     return(base.VisitJoin(expression));
 }
 protected override Expression VisitJoin(SqlJoinExpression expression)
 {
     this.hashCode ^= expression.JoinType.GetHashCode();
     return base.VisitJoin(expression);
 }
        protected override Expression VisitJoin(SqlJoinExpression expression)
        {
            SqlJoinExpression current;
            if (!TryGetCurrent(expression, out current))
            {
                return expression;
            }

            if (!(this.result &= current.JoinType == expression.JoinType))
            {
                return expression;
            }

            if (!(this.result &= current.NodeType == expression.NodeType))
            {
                return expression;
            }

            if (!(this.result &= current.Type == expression.Type))
            {
                return expression;
            }

            this.currentObject = current.Left;
            this.Visit(expression.Left);
            if (!this.result)
            {
                return expression;
            }

            this.currentObject = current.Right;
            this.Visit(expression.Right);
            if (!this.result)
            {
                return expression;
            }

            this.currentObject = current.JoinCondition;
            this.Visit(expression.JoinCondition);
            if (!this.result)
            {
                return expression;
            }

            this.currentObject = current.Aliases;
            this.VisitObjectList(expression.Aliases);
            if (!this.result)
            {
                return expression;
            }

            this.currentObject = current;
            return expression;
        }
		protected override Expression VisitJoin(SqlJoinExpression join)
		{
			var left = this.Visit(join.Left);
			var right = this.Visit(join.Right);
			var condition = this.Visit(join.JoinCondition);

			if (condition?.Type.GetUnwrappedNullableType() == typeof(bool) && condition is BitBooleanExpression)
			{
				condition = Expression.Equal(condition, Expression.Constant(true, condition.Type));
			}

			if (left != join.Left || right != join.Right || condition != join.JoinCondition)
			{
				return new SqlJoinExpression(join.Type, join.JoinType, left, right, condition);
			}

			return join;
		}
Пример #14
0
        protected override Expression VisitJoin(SqlJoinExpression join)
        {
            this.VisitSource(join.Left);

            this.WriteLine();

            switch (join.JoinType)
            {
            case SqlJoinType.Cross:
                this.Write(" CROSS JOIN ");
                break;
            case SqlJoinType.Inner:
                this.Write(" INNER JOIN ");
                break;
            case SqlJoinType.Left:
                this.Write(" LEFT JOIN ");
                break;
            case SqlJoinType.Right:
                this.Write(" RIGHT JOIN ");
                break;
            case SqlJoinType.Outer:
                this.Write(" FULL OUTER JOIN ");
                break;
            case SqlJoinType.CrossApply:
                this.Write(" CROSS APPLY ");
                break;
            case SqlJoinType.OuterApply:
                this.Write(" OUTER APPLY ");
                break;
            default:
                throw new ArgumentOutOfRangeException(nameof(join), join.JoinType, "Join type incorrect");
            }

            this.VisitSource(join.Right);

            if (join.JoinCondition != null)
            {
                using (this.AcquireIndentationContext())
                {
                    this.Write("ON ");

                    this.Visit(join.JoinCondition);
                }
            }

            return join;
        }
Пример #15
0
		protected virtual Expression VisitJoin(SqlJoinExpression join)
		{
			var left = this.Visit(join.Left);
			var right = this.Visit(join.Right);
			var condition = this.Visit(join.JoinCondition);

			if (condition == null)
			{
				this.Visit(join.JoinCondition);
			}

			if (left != join.Left || right != join.Right || condition != join.JoinCondition)
			{
				return new SqlJoinExpression(join.Type, join.JoinType, left, right, condition);
			}

			return join;
		}
Пример #16
0
		protected override Expression VisitJoin(SqlJoinExpression join)
		{
			this.VisitSource(join.Left);

			this.WriteLine();

			this.Write(join.JoinType);

			this.VisitSource(join.Right);

			if (join.JoinCondition != null)
			{
				using (this.AcquireIndentationContext())
				{
					this.Write("ON ");

					this.Visit(join.JoinCondition);
				}
			}

			return join;
		}
Пример #17
0
        protected override Expression VisitJoin(SqlJoinExpression join)
        {
            this.hashCode ^= ((int)join.JoinType) << 16;

            return(base.VisitJoin(join));
        }