public override Expression GetDeleteExpression(MappingEntity entity, Expression instance, LambdaExpression deleteCheck)
        {
            var commands = new List <Expression>();
            var tables   = this.mapping.GetTables(entity);

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

            foreach (var table in this.GetDependencyOrderedTables(entity).Reverse())
            {
                var tex = new DbTableExpression(new TableAlias(), entity, this.mapping.GetTableName(table));
                var where = this.GetIdentityCheck(tex, entity, instance);

                commands.Add(new DbDeleteCommand(tex, where));
            }

            var block = new DbBlockCommand(commands) as Expression;

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

            return(block);
        }
        protected DbBlockCommand UpdateBlock(DbBlockCommand block, IList <Expression> commands)
        {
            if (block.Commands != commands)
            {
                return(new DbBlockCommand(commands));
            }

            return(block);
        }
        public override Expression GetUpdateExpression(MappingEntity entity, Expression instance, LambdaExpression updateCheck, LambdaExpression selector, Expression exp)
        {
            var tables = this.mapping.GetTables(entity);

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

            var commands = new List <Expression>();

            foreach (var table in this.GetDependencyOrderedTables(entity))
            {
                var tex         = new DbTableExpression(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 DbUpdateCommand(tex, where, assignments));
            }

            if (selector != null)
            {
                commands.Add(new DbIFCommand
                             (
                                 this.Translator.Linguist.Language.GetRowsAffectedExpression(commands[commands.Count - 1]).GreaterThan(Expression.Constant(0)),
                                 this.GetUpdateResult(entity, instance, selector), exp)
                             );
            }
            else if (exp != null)
            {
                commands.Add(new DbIFCommand
                             (
                                 this.Translator.Linguist.Language.GetRowsAffectedExpression(commands[commands.Count - 1]).LessThanOrEqual(Expression.Constant(0)),
                                 exp,
                                 null
                             ));
            }

            var block = new DbBlockCommand(commands) as Expression;

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

            return(block);
        }
        protected virtual bool CompareBlock(DbBlockCommand x, DbBlockCommand 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]) == false)
                {
                    return(false);
                }
            }

            return(true);
        }
Beispiel #5
0
 protected override Expression VisitBlock(DbBlockCommand block)
 {
     throw new NotSupportedException();
 }
 protected virtual Expression VisitBlock(DbBlockCommand block)
 {
     return(this.UpdateBlock(block, this.VisitExpressionList(block.Commands)));
 }
 protected override Expression VisitBlock(DbBlockCommand block)
 {
     return(MakeSequence(this.VisitExpressionList(block.Commands)));
 }