예제 #1
0
 protected BlockCommand UpdateBlock(BlockCommand block, IList <Expression> commands)
 {
     if (block.Commands != commands)
     {
         return(new BlockCommand(commands));
     }
     return(block);
 }
        protected virtual bool CompareBlock(BlockCommand x, BlockCommand y)
        {
            if (x.Commands.Count != y.Commands.Count)
            {
                return(false);
            }
            int num   = 0;
            int count = x.Commands.Count;

            while (num < count)
            {
                if (!this.Compare(x.Commands[num], y.Commands[num]))
                {
                    return(false);
                }
                num++;
            }
            return(true);
        }
예제 #3
0
        public override Expression GetUpdateExpression(MappingEntity entity, Expression instance, LambdaExpression updateCheck, LambdaExpression selector, Expression @else)
        {
            if (this.mapping.GetTables(entity).Count < 2)
            {
                return(base.GetUpdateExpression(entity, instance, updateCheck, selector, @else));
            }
            List <Expression> commands = new List <Expression>();

            using (IEnumerator <MappingTable> enumerator = this.GetDependencyOrderedTables(entity).GetEnumerator())
            {
                while (enumerator.MoveNext())
                {
                    Func <MappingEntity, MemberInfo, bool> fnIncludeColumn = null;
                    MappingTable    table      = enumerator.Current;
                    TableExpression expression = new TableExpression(new TableAlias(), entity, this.mapping.GetTableName(table));
                    if (fnIncludeColumn == null)
                    {
                        fnIncludeColumn = (e, m) => (this.mapping.GetAlias(e, m) == this.mapping.GetAlias(table)) && this.mapping.IsUpdatable(e, m);
                    }
                    IEnumerable <ColumnAssignment> assignments = this.GetColumnAssignments(expression, instance, entity, fnIncludeColumn, null);
                    Expression where = this.GetIdentityCheck(expression, entity, instance);
                    commands.Add(new UpdateCommand(expression, where, assignments));
                }
            }
            if (selector != null)
            {
                commands.Add(new IFCommand(this.Translator.Linguist.Language.GetRowsAffectedExpression(commands[commands.Count - 1]).GreaterThan(Expression.Constant(0)), this.GetUpdateResult(entity, instance, selector), @else));
            }
            else if (@else != null)
            {
                commands.Add(new IFCommand(this.Translator.Linguist.Language.GetRowsAffectedExpression(commands[commands.Count - 1]).LessThanOrEqual(Expression.Constant(0)), @else, null));
            }
            Expression ifTrue = new BlockCommand(commands);

            if (updateCheck != null)
            {
                return(new IFCommand(this.GetEntityStateTest(entity, instance, updateCheck), ifTrue, null));
            }
            return(ifTrue);
        }
예제 #4
0
        public override Expression GetDeleteExpression(MappingEntity entity, Expression instance, LambdaExpression deleteCheck)
        {
            if (this.mapping.GetTables(entity).Count < 2)
            {
                return(base.GetDeleteExpression(entity, instance, deleteCheck));
            }
            List <Expression> commands = new List <Expression>();

            foreach (MappingTable table in this.GetDependencyOrderedTables(entity).Reverse <MappingTable>())
            {
                TableExpression root = new TableExpression(new TableAlias(), entity, this.mapping.GetTableName(table));
                Expression where = this.GetIdentityCheck(root, entity, instance);
                commands.Add(new DeleteCommand(root, where));
            }
            Expression ifTrue = new BlockCommand(commands);

            if (deleteCheck != null)
            {
                return(new IFCommand(this.GetEntityStateTest(entity, instance, deleteCheck), ifTrue, null));
            }
            return(ifTrue);
        }
예제 #5
0
 protected override Expression VisitBlock(BlockCommand block)
 {
     throw new NotSupportedException();
 }
 protected override Expression VisitBlock(BlockCommand block)
 {
     return(MakeSequence(this.VisitExpressionList(block.Commands)));
 }
예제 #7
0
        protected virtual Expression VisitBlock(BlockCommand block)
        {
            ReadOnlyCollection <Expression> commands = this.VisitExpressionList(block.Commands);

            return(this.UpdateBlock(block, commands));
        }