/// <summary> /// This is an internal API that supports the Entity Framework Core infrastructure and not subject to /// the same compatibility standards as public APIs. It may be changed or removed without notice in /// any release. You should only use it directly in your code with extreme caution and knowing that /// doing so can result in application failures when updating to a new Entity Framework Core release. /// </summary> protected override void GenerateSetOperationOperand(SetOperationBase setOperation, SelectExpression operand) { Check.NotNull(setOperation, nameof(setOperation)); Check.NotNull(operand, nameof(operand)); // Sqlite doesn't support parentheses around set operation operands Visit(operand); }
/// <summary> /// Generates a set operation in the relational command. /// </summary> /// <param name="setOperation"> A set operation to print. </param> protected virtual void GenerateSetOperation([NotNull] SetOperationBase setOperation) { Check.NotNull(setOperation, nameof(setOperation)); GenerateSetOperationOperand(setOperation, setOperation.Source1); _relationalCommandBuilder.AppendLine(); _relationalCommandBuilder.AppendLine($"{GetSetOperation(setOperation)}{(setOperation.IsDistinct ? "" : " ALL")}"); GenerateSetOperationOperand(setOperation, setOperation.Source2);
private void GenerateSetOperationHelper(SetOperationBase setOperation) { _relationalCommandBuilder.AppendLine("("); using (_relationalCommandBuilder.Indent()) { GenerateSetOperation(setOperation); } _relationalCommandBuilder.AppendLine() .Append(")") .Append(AliasSeparator) .Append(_sqlGenerationHelper.DelimitIdentifier(setOperation.Alias)); }
protected virtual void GenerateSetOperation(SetOperationBase setOperation) { string getSetOperation() => setOperation switch { ExceptExpression _ => "EXCEPT", IntersectExpression _ => "INTERSECT", UnionExpression _ => "UNION", _ => throw new InvalidOperationException("Unknown SetOperationType."), }; GenerateSetOperationOperand(setOperation, setOperation.Source1); _relationalCommandBuilder.AppendLine(); _relationalCommandBuilder.AppendLine($"{getSetOperation()}{(setOperation.IsDistinct ? "" : " ALL")}"); GenerateSetOperationOperand(setOperation, setOperation.Source2); }
protected virtual void GenerateSetOperation([NotNull] SetOperationBase setOperation) { Check.NotNull(setOperation, nameof(setOperation)); string getSetOperation() => setOperation switch { ExceptExpression _ => "EXCEPT", IntersectExpression _ => "INTERSECT", UnionExpression _ => "UNION", _ => throw new InvalidOperationException(CoreStrings.UnknownEntity("SetOperationType")), }; GenerateSetOperationOperand(setOperation, setOperation.Source1); _relationalCommandBuilder.AppendLine(); _relationalCommandBuilder.AppendLine($"{getSetOperation()}{(setOperation.IsDistinct ? "" : " ALL")}"); GenerateSetOperationOperand(setOperation, setOperation.Source2); }
protected virtual void GenerateSetOperationOperand(SetOperationBase setOperation, SelectExpression operand) { // INTERSECT has higher precedence over UNION and EXCEPT, but otherwise evaluation is left-to-right. // To preserve meaning, add parentheses whenever a set operation is nested within a different set operation. if (IsNonComposedSetOperation(operand) && operand.Tables[0].GetType() != setOperation.GetType()) { _relationalCommandBuilder.AppendLine("("); using (_relationalCommandBuilder.Indent()) { Visit(operand); } _relationalCommandBuilder.AppendLine().Append(")"); } else { Visit(operand); } }
//from ef core private static bool IsNonComposedSetOperation(SelectExpression selectExpression) { if (selectExpression.Offset == null && selectExpression.Limit == null && !selectExpression.IsDistinct && selectExpression.Predicate == null && selectExpression.Having == null && selectExpression.Orderings.Count == 0 && selectExpression.GroupBy.Count == 0 && selectExpression.Tables.Count == 1) { TableExpressionBase tableExpressionBase = selectExpression.Tables[0]; SetOperationBase setOperation = tableExpressionBase as SetOperationBase; if (setOperation != null && selectExpression.Projection.Count == setOperation.Source1.Projection.Count) { return(selectExpression.Projection.Select(delegate(ProjectionExpression pe, int index) { ColumnExpression columnExpression = pe.Expression as ColumnExpression; if (columnExpression != null && string.Equals(columnExpression.Table.Alias, setOperation.Alias, StringComparison.OrdinalIgnoreCase)) { return string.Equals(columnExpression.Name, setOperation.Source1.Projection[index].Alias, StringComparison.OrdinalIgnoreCase); } return false; }).All((bool e) => e)); } } return(false); }
public void P_GenerateSetOperation(SetOperationBase setOperation) { this.GenerateSetOperation(setOperation); }
static string GetSetOperation(SetOperationBase operation) => operation switch {
protected override void GenerateSetOperationOperand(SetOperationBase setOperation, SelectExpression operand) { // Sqlite doesn't support parentheses around set operation operands Visit(operand); }