예제 #1
0
 protected virtual void VisitRelation(ITableConfig table, IBinaryExpressionBuilder expression)
 {
     this.Builder.AppendFormat("{0} ", this.Database.QueryFactory.Dialect.JOIN);
     this.VisitTable(this.CreateTable(table));
     this.Builder.AppendFormat("{0} ", this.Database.QueryFactory.Dialect.ON);
     this.Visit(expression);
 }
예제 #2
0
        protected override void VisitBinary(IBinaryExpressionBuilder expression)
        {
            var column    = expression.GetExpression <IColumnBuilder>();
            var parameter = expression.GetExpression <IParameterBuilder>();

            //TODO: This should be done in the re-writer phase but don't have anything to emit the parentheses with.
            //column = @param for a nullable type. We need to create the appropriate filter as null cannot be directly compared.
            if (column != null && column.Column.ColumnType.IsNullable && expression.Operator != null && expression.Operator.Operator == QueryOperator.Equal && parameter != null)
            {
                this.Builder.AppendFormat("{0} ", this.Database.QueryFactory.Dialect.OPEN_PARENTHESES);
                this.Builder.AppendFormat("{0} ", this.Database.QueryFactory.Dialect.OPEN_PARENTHESES);
                this.Visit(parameter);
                this.Builder.AppendFormat("{0} ", this.Database.QueryFactory.Dialect.IS);
                this.Builder.AppendFormat("{0} ", this.Database.QueryFactory.Dialect.NULL);
                this.Builder.AppendFormat("{0} ", this.Database.QueryFactory.Dialect.AND_ALSO);
                this.Visit(column);
                this.Builder.AppendFormat("{0} ", this.Database.QueryFactory.Dialect.IS);
                this.Builder.AppendFormat("{0} ", this.Database.QueryFactory.Dialect.NULL);
                this.Builder.AppendFormat("{0} ", this.Database.QueryFactory.Dialect.CLOSE_PARENTHESES);
                this.Builder.AppendFormat("{0} ", this.Database.QueryFactory.Dialect.OR_ELSE);
                base.VisitBinary(expression);
                this.Builder.AppendFormat("{0} ", this.Database.QueryFactory.Dialect.CLOSE_PARENTHESES);
            }
            else
            {
                base.VisitBinary(expression);
            }
        }
예제 #3
0
        protected virtual IBinaryExpressionBuilder Combine(IBinaryExpressionBuilder left, IBinaryExpressionBuilder right, QueryOperator @operator = QueryOperator.None)
        {
            if (object.ReferenceEquals(left, right))
            {
                return(left ?? right);
            }
            if (this.HasCommonParent(left, right))
            {
                var expression = left.Parent ?? right.Parent;
                if (expression is IBinaryExpressionBuilder)
                {
                    return((IBinaryExpressionBuilder)expression);
                }
            }
            var parent = left.Parent as IBinaryExpressionBuilder ?? right.Parent as IBinaryExpressionBuilder;

            if (parent != null)
            {
                return(parent.Fragment <IBinaryExpressionBuilder>().With(expression =>
                {
                    expression.Left = left;
                    expression.Operator = @operator == QueryOperator.None ? parent.Operator : parent.CreateOperator(@operator);
                    expression.Right = right;
                }));
            }
            throw new NotImplementedException();
        }
예제 #4
0
        public static IEnumerable <IBinaryExpressionBuilder> GetLeaves(this IBinaryExpressionBuilder expression)
        {
            var leaves = expression
                         .Flatten <IBinaryExpressionBuilder>()
                         .Where(binary => binary.IsLeaf)
                         .Distinct();

            return(leaves);
        }
예제 #5
0
        protected virtual bool HasCommonParent(IBinaryExpressionBuilder left, IBinaryExpressionBuilder right)
        {
            var parent = left.Parent as IBinaryExpressionBuilder ?? right.Parent as IBinaryExpressionBuilder;

            if (parent != null)
            {
                if (new[] { parent.Left, parent.Right }.Contains(new[] { left, right }))
                {
                    return(true);
                }
            }
            return(false);
        }
예제 #6
0
        protected virtual bool IsNotNull(IBinaryExpressionBuilder expression)
        {
            var right = expression.Right as IOperatorBuilder;

            if (expression.Operator == null || right == null)
            {
                return(false);
            }
            if (expression.Operator.Operator != QueryOperator.NotEqual || right.Operator != QueryOperator.Null)
            {
                return(false);
            }
            return(true);
        }
예제 #7
0
 protected virtual void VisitBinary(IBinaryExpressionBuilder expression)
 {
     this.Visit(expression.Left);
     if (this.IsNull(expression))
     {
         this.Visit(this.CreateOperator(QueryOperator.Is));
         this.Visit(this.CreateOperator(QueryOperator.Null));
     }
     else if (this.IsNotNull(expression))
     {
         this.Visit(this.CreateOperator(QueryOperator.Is));
         this.Visit(this.CreateOperator(QueryOperator.Not));
         this.Visit(this.CreateOperator(QueryOperator.Null));
     }
     else
     {
         this.Visit(expression.Operator);
         this.Visit(expression.Right);
     }
 }
예제 #8
0
 public EntityRelation(IRelationConfig relation, ITableConfig table, IBinaryExpressionBuilder expression)
 {
     this.Relation   = relation;
     this.Table      = table;
     this.Expression = expression;
 }
예제 #9
0
 public PendingEntityRelation(IRelationConfig relation, IBinaryExpressionBuilder expression)
 {
     this.Relation   = relation;
     this.Expression = expression;
 }
예제 #10
0
 protected virtual bool HasCommonTable(IBinaryExpressionBuilder left, IBinaryExpressionBuilder right)
 {
     return(left.GetTables().Intersect(right.GetTables()).Any());
 }
예제 #11
0
 protected virtual bool Extern(IEntityRelation relation, IBinaryExpressionBuilder expression)
 {
     //Nothing to do.
     return(true);
 }