Ejemplo n.º 1
0
        public override Expression GetDeleteExpression(MappingEntity entity, Expression instance, LambdaExpression deleteCheck)
        {
            var tables = this.mapping.GetTables(entity);

            if (tables.Count < 2)
            {
                return(base.GetDeleteExpression(entity, instance, deleteCheck));
            }

            var commands = new List <Expression>();

            foreach (var table in this.GetDependencyOrderedTables(entity).Reverse())
            {
                TableExpression tex = new TableExpression(new TableAlias(), entity, this.mapping.GetTableName(table));
                var where = this.GetIdentityCheck(tex, entity, instance);
                commands.Add(new DeleteCommand(tex, where));
            }

            Expression block = new BlockCommand(commands);

            if (deleteCheck != null)
            {
                var test = this.GetEntityStateTest(entity, instance, deleteCheck);
                return(new IFCommand(test, block, null));
            }

            return(block);
        }
Ejemplo n.º 2
0
 protected BlockCommand UpdateBlock(BlockCommand block, IList <Expression> commands)
 {
     if (block.Commands != commands)
     {
         return(new BlockCommand(commands));
     }
     return(block);
 }
Ejemplo n.º 3
0
        public override Expression GetUpdateExpression(MappingEntity entity, Expression instance, LambdaExpression updateCheck, LambdaExpression selector, Expression @else)
        {
            var tables = this.mapping.GetTables(entity);

            if (tables.Count < 2)
            {
                return(base.GetUpdateExpression(entity, instance, updateCheck, selector, @else));
            }

            var commands = new List <Expression>();

            foreach (var table in this.GetDependencyOrderedTables(entity))
            {
                TableExpression tex         = new TableExpression(new TableAlias(), entity, this.mapping.GetTableName(table));
                var             assignments = this.GetColumnAssignments(tex, instance, entity, (e, m) => this.mapping.GetAlias(e, m) == this.mapping.GetAlias(table) && this.mapping.IsUpdatable(e, m), null);
                var where = this.GetIdentityCheck(tex, entity, instance);
                commands.Add(new UpdateCommand(tex, 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 block = new BlockCommand(commands);

            if (updateCheck != null)
            {
                var test = this.GetEntityStateTest(entity, instance, updateCheck);
                return(new IFCommand(test, block, null));
            }

            return(block);
        }
Ejemplo n.º 4
0
 protected virtual bool CompareBlock(BlockCommand x, BlockCommand y)
 {
     if (x.Commands.Count != y.Commands.Count)
     {
         return(false);
     }
     for (int i = 0, n = x.Commands.Count; i < n; i++)
     {
         if (!this.Compare(x.Commands[i], y.Commands[i]))
         {
             return(false);
         }
     }
     return(true);
 }
Ejemplo n.º 5
0
        //protected override Expression VisitDelete(DeleteCommand delete)
        //{
        //    return this.BuildExecuteCommand(delete);
        //}

        protected override Expression VisitBlock(BlockCommand block)
        {
            return(MakeSequence(this.VisitExpressionList(block.Commands)));
        }
Ejemplo n.º 6
0
 protected override Expression VisitBlock(BlockCommand block)
 {
     throw new NotSupportedException();
 }
Ejemplo n.º 7
0
        protected virtual Expression VisitBlock(BlockCommand block)
        {
            var commands = this.VisitExpressionList(block.Commands);

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