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 = SqlAliasReferenceReplacer.Replace(projection.Select.Where, alias, table.Name); return(new SqlDeleteExpression(table, where)); }
protected override Expression VisitInsertInto(SqlInsertIntoExpression insertIntoExpression) { if (!(insertIntoExpression.Source is SqlProjectionExpression projection)) { 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 = SqlAliasReferenceReplacer.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)); }