Inheritance: Shaolinq.Persistence.Linq.Expressions.SqlExpressionVisitor
        protected override Expression VisitInsertInto(SqlInsertIntoExpression insertIntoExpression)
        {
            var projection = insertIntoExpression.Source as SqlProjectionExpression;

            if (projection == null)
            {
                return(insertIntoExpression);
            }

            if (projection.Select.From.NodeType != (ExpressionType)SqlExpressionType.Table)
            {
                throw new NotSupportedException();
            }

            var table = (SqlTableExpression)projection.Select.From;
            var alias = table.Alias;

            var where = AliasReferenceReplacer.Replace(projection.Select.Where, alias, table.Name);

            if (where != null)
            {
                throw new InvalidOperationException("Inserts must only be performed on pure tables");
            }

            return(new SqlInsertIntoExpression(table, insertIntoExpression.ColumnNames, insertIntoExpression.ReturningAutoIncrementColumnNames, insertIntoExpression.ValueExpressions));
        }
Example #2
0
        protected override Expression VisitDelete(SqlDeleteExpression deleteExpression)
        {
            if (!(deleteExpression.Source is SqlProjectionExpression projection))
            {
                return(deleteExpression);
            }

            if (projection.Select.From.NodeType != (ExpressionType)SqlExpressionType.Table)
            {
                throw new NotSupportedException();
            }

            var table = (SqlTableExpression)projection.Select.From;
            var alias = table.Alias;

            var where = AliasReferenceReplacer.Replace(projection.Select.Where, alias, table.Name);

            return(new SqlDeleteExpression(table, where));
        }
Example #3
0
        protected override Expression VisitUpdate(SqlUpdateExpression updateExpression)
        {
            var projection = updateExpression.Source as SqlProjectionExpression;

            if (projection == null)
            {
                return(updateExpression);
            }

            if (projection.Select.From.NodeType != (ExpressionType)SqlExpressionType.Table)
            {
                throw new NotSupportedException();
            }

            var table = (SqlTableExpression)projection.Select.From;
            var alias = table.Alias;

            var where = AliasReferenceReplacer.Replace(projection.Select.Where, alias, table.Name);

            return(new SqlUpdateExpression(table, updateExpression.Assignments, where));
        }