Esempio n. 1
0
        private bool TrivialWhere(DeleteExpression delete, SelectExpression select)
        {
            if (select.SelectRoles != 0)
            {
                return(false);
            }

            if (delete.Where == null)
            {
                return(false);
            }

            if (delete.Where.NodeType != ExpressionType.Equal)
            {
                return(false);
            }

            var b = (BinaryExpression)delete.Where;

            var ce1 = RemoveConvert(b.Left) as ColumnExpression;
            var ce2 = RemoveConvert(b.Right) as ColumnExpression;

            if (ce1 == null || ce2 == null)
            {
                return(false);
            }

            ce1 = ResolveColumn(ce1, select);
            ce2 = ResolveColumn(ce2, select);

            return(ce1.Name == ce2.Name && ce1.Alias.Equals(ce2.Alias));
        }
Esempio n. 2
0
 protected virtual bool CompareDelete(DeleteExpression a, DeleteExpression b)
 {
     return(a.Table == b.Table &&
            a.UseHistoryTable == b.UseHistoryTable &&
            Compare(a.Source, b.Source) &&
            Compare(a.Where, b.Where));
 }
Esempio n. 3
0
        protected internal override Expression VisitDelete(DeleteExpression delete)
        {
            if (delete.ReturnRowCount == false)
            {
                return(delete);
            }

            return(new DeleteExpression(delete.Table, delete.UseHistoryTable, delete.Source, delete.Where, returnRowCount: false));
        }
Esempio n. 4
0
        protected internal virtual Expression VisitDelete(DeleteExpression delete)
        {
            var source = VisitSource(delete.Source);

            var where = Visit(delete.Where);
            if (source != delete.Source || where != delete.Where)
            {
                return(new DeleteExpression(delete.Table, delete.UseHistoryTable, (SourceWithAliasExpression)source, where, delete.ReturnRowCount));
            }
            return(delete);
        }
Esempio n. 5
0
        protected internal override Expression VisitDelete(DeleteExpression delete)
        {
            var where = Visit(delete.Where);
            var source = Visit(delete.Source);

            if (source != delete.Source || where != delete.Where)
            {
                return(new DeleteExpression(delete.Table, (SourceWithAliasExpression)source, where));
            }
            return(delete);
        }
Esempio n. 6
0
 protected internal override Expression VisitDelete(DeleteExpression delete)
 {
     sb.Append("DELETE ");
     sb.Append(delete.Name.ToString());
     this.AppendNewLine(Indentation.Same);
     sb.Append("FROM ");
     VisitSource(delete.Source);
     if (delete.Where != null)
     {
         this.AppendNewLine(Indentation.Same);
         sb.Append("WHERE ");
         Visit(delete.Where);
     }
     return(delete);
 }
Esempio n. 7
0
        protected internal override Expression VisitDelete(DeleteExpression delete)
        {
            GetColumnCollector(delete.Source.KnownAliases).Visit(delete.Where);

            var source = Visit(delete.Source);

            var where = Visit(delete.Where);

            if (source != delete.Source || where != delete.Where)
            {
                return(new DeleteExpression(delete.Table, delete.UseHistoryTable, (SourceWithAliasExpression)source, where));
            }

            return(delete);
        }
Esempio n. 8
0
        protected internal override Expression VisitDelete(DeleteExpression delete)
        {
            var select = (SelectExpression)delete.Source;

            if (select.From is not TableExpression table || delete.Table != table.Table)
            {
                return(delete);
            }

            if (!TrivialWhere(delete, select))
            {
                return(delete);
            }

            return(new DeleteExpression(delete.Table, delete.UseHistoryTable, table, select.Where, delete.ReturnRowCount));
        }
Esempio n. 9
0
        protected internal override Expression VisitDelete(DeleteExpression delete)
        {
            var select = delete.Source as SelectExpression;

            TableExpression table = select.From as TableExpression;

            if (table == null || delete.Table != table.Table)
            {
                return(delete);
            }

            if (!TrivialWhere(delete, select))
            {
                return(delete);
            }

            return(new DeleteExpression(delete.Table, table, select.Where));
        }