Skip to content

Commit

Permalink
API review changes (#28728)
Browse files Browse the repository at this point in the history
  • Loading branch information
smitpatel authored Aug 15, 2022
1 parent adf8eb4 commit f73f511
Show file tree
Hide file tree
Showing 11 changed files with 22 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1503,7 +1503,7 @@ private static Expression ConvertObjectArrayEqualityComparison(Expression left,
l = l.Type.IsNullableType() ? l : Expression.Convert(l, r.Type);
}
return ExpressionExtensions.BuildEqualsExpression(l, r);
return ExpressionExtensions.CreateEqualsExpression(l, r);
})
.Aggregate((a, b) => Expression.AndAlso(a, b));

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -535,7 +535,7 @@ private static ShapedQueryExpression CreateShapedQueryExpressionStatic(IEntityTy
var left = RemapLambdaBody(outer, outerKeySelector);
var right = RemapLambdaBody(inner, innerKeySelector);

var joinCondition = TranslateExpression(EntityFrameworkCore.Infrastructure.ExpressionExtensions.BuildEqualsExpression(left, right));
var joinCondition = TranslateExpression(EntityFrameworkCore.Infrastructure.ExpressionExtensions.CreateEqualsExpression(left, right));

var (outerKeyBody, innerKeyBody) = DecomposeJoinCondition(joinCondition);

Expand Down Expand Up @@ -1251,7 +1251,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
: foreignKey.Properties,
makeNullable);

var keyComparison = EntityFrameworkCore.Infrastructure.ExpressionExtensions.BuildEqualsExpression(outerKey, innerKey);
var keyComparison = EntityFrameworkCore.Infrastructure.ExpressionExtensions.CreateEqualsExpression(outerKey, innerKey);

var predicate = makeNullable
? Expression.AndAlso(
Expand Down
4 changes: 3 additions & 1 deletion src/EFCore.Relational/Diagnostics/CommandSource.cs
Original file line number Diff line number Diff line change
Expand Up @@ -76,5 +76,7 @@ public enum CommandSource
/// <summary>
/// The command was generated as part of an 'ExecuteUpdate' operation.
/// </summary>
ExecuteUpdate,
#pragma warning disable CS0618 // Type or member is obsolete
ExecuteUpdate = BulkUpdate,
#pragma warning restore CS0618 // Type or member is obsolete
}
Original file line number Diff line number Diff line change
Expand Up @@ -608,7 +608,7 @@ private SqlExpression CreateJoinPredicate(
}

private SqlExpression CreateJoinPredicate(Expression outerKey, Expression innerKey)
=> TranslateExpression(EntityFrameworkCore.Infrastructure.ExpressionExtensions.BuildEqualsExpression(outerKey, innerKey))!;
=> TranslateExpression(EntityFrameworkCore.Infrastructure.ExpressionExtensions.CreateEqualsExpression(outerKey, innerKey))!;

/// <inheritdoc />
protected override ShapedQueryExpression? TranslateLastOrDefault(
Expand Down Expand Up @@ -1064,7 +1064,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
QueryableMethods.AnyWithPredicate.MakeGenericMethod(clrType),
source,
Expression.Quote(Expression.Lambda(
Infrastructure.ExpressionExtensions.BuildEqualsExpression(innerParameter, entityParameter),
Infrastructure.ExpressionExtensions.CreateEqualsExpression(innerParameter, entityParameter),
innerParameter)));
}

Expand Down Expand Up @@ -1126,7 +1126,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
// We generate equality between property = value while translating sothat value infer tye type mapping from property correctly.
// Later we decompose it back into left/right components so that the equality is not in the tree which can get affected by
// null semantics or other visitor.
var setter = Infrastructure.ExpressionExtensions.BuildEqualsExpression(left, right);
var setter = Infrastructure.ExpressionExtensions.CreateEqualsExpression(left, right);
var translation = _sqlTranslator.Translate(setter);
if (translation is SqlBinaryExpression { OperatorType: ExpressionType.Equal, Left: ColumnExpression column } sqlBinaryExpression)
{
Expand Down Expand Up @@ -1512,7 +1512,7 @@ protected override Expression VisitExtension(Expression extensionExpression)
: foreignKey.Properties,
makeNullable);

var keyComparison = Infrastructure.ExpressionExtensions.BuildEqualsExpression(outerKey, innerKey);
var keyComparison = Infrastructure.ExpressionExtensions.CreateEqualsExpression(outerKey, innerKey);

var predicate = makeNullable
? Expression.AndAlso(
Expand Down Expand Up @@ -1604,7 +1604,7 @@ outerKey is NewArrayExpression newArrayExpression
makeNullable);

var joinPredicate = _sqlTranslator.Translate(
EntityFrameworkCore.Infrastructure.ExpressionExtensions.BuildEqualsExpression(outerKey, innerKey))!;
EntityFrameworkCore.Infrastructure.ExpressionExtensions.CreateEqualsExpression(outerKey, innerKey))!;
// Following conditions should match conditions for pushdown on outer during SelectExpression.AddJoin method
var pushdownRequired = _selectExpression.Limit != null
|| _selectExpression.Offset != null
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1440,7 +1440,7 @@ private static Expression ConvertObjectArrayEqualityComparison(Expression left,

return leftExpressions.Zip(
rightExpressions,
(l, r) => Infrastructure.ExpressionExtensions.BuildEqualsExpression(l, r))
(l, r) => Infrastructure.ExpressionExtensions.CreateEqualsExpression(l, r))
.Aggregate((a, b) => Expression.AndAlso(a, b));
}

Expand Down Expand Up @@ -1571,7 +1571,7 @@ private bool TryRewriteEntityEquality(
var condition = nullComparedEntityType.GetNonPrincipalSharedNonPkProperties(table)
.Where(e => !e.IsNullable)
.Select(
p => Infrastructure.ExpressionExtensions.BuildEqualsExpression(
p => Infrastructure.ExpressionExtensions.CreateEqualsExpression(
CreatePropertyAccessExpression(nonNullEntityReference, p),
Expression.Constant(null, p.ClrType.MakeNullable()),
nodeType != ExpressionType.Equal))
Expand All @@ -1584,7 +1584,7 @@ private bool TryRewriteEntityEquality(

result = Visit(
nullComparedEntityTypePrimaryKeyProperties.Select(
p => Infrastructure.ExpressionExtensions.BuildEqualsExpression(
p => Infrastructure.ExpressionExtensions.CreateEqualsExpression(
CreatePropertyAccessExpression(nonNullEntityReference, p),
Expression.Constant(null, p.ClrType.MakeNullable()),
nodeType != ExpressionType.Equal))
Expand Down Expand Up @@ -1636,7 +1636,7 @@ private bool TryRewriteEntityEquality(

result = Visit(
primaryKeyProperties.Select(
p => Infrastructure.ExpressionExtensions.BuildEqualsExpression(
p => Infrastructure.ExpressionExtensions.CreateEqualsExpression(
CreatePropertyAccessExpression(left, p),
CreatePropertyAccessExpression(right, p),
nodeType != ExpressionType.Equal))
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/ChangeTracking/ValueComparer`.cs
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ public ValueComparer(

return Expression.Lambda<Func<T?, T?, bool>>(
typedEquals == null
? Infrastructure.ExpressionExtensions.BuildEqualsExpression(param1, param2)
? Infrastructure.ExpressionExtensions.CreateEqualsExpression(param1, param2)
: Expression.Call(typedEquals, param1, param2),
param1, param2);
}
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Extensions/Internal/ExpressionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -223,7 +223,7 @@ static Expression GenerateEqualExpression(
=> property.ClrType.IsValueType
&& property.ClrType.UnwrapNullableType() is Type nonNullableType
&& !(nonNullableType == typeof(bool) || nonNullableType.IsNumeric() || nonNullableType.IsEnum)
? Infrastructure.ExpressionExtensions.BuildEqualsExpression(
? Infrastructure.ExpressionExtensions.CreateEqualsExpression(
Expression.Call(
EF.PropertyMethod.MakeGenericMethod(typeof(object)),
entityParameterExpression,
Expand Down
2 changes: 1 addition & 1 deletion src/EFCore/Infrastructure/ExpressionExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -394,7 +394,7 @@ private static readonly MethodInfo ObjectEqualsMethodInfo
/// <param name="right">The right expression in equality comparison.</param>
/// <param name="negated">If the comparison is non-equality.</param>
/// <returns>An expression to compare left and right expressions.</returns>
public static Expression BuildEqualsExpression(
public static Expression CreateEqualsExpression(
Expression left,
Expression right,
bool negated = false)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -302,7 +302,7 @@ protected Expression ExpandSkipNavigation(
QueryableMethods.Where.MakeGenericMethod(innerSourceElementType),
innerSource,
Expression.Quote(Expression.Lambda(
Infrastructure.ExpressionExtensions.BuildEqualsExpression(outerKey,innerKey), innerSourceParameter))),
Infrastructure.ExpressionExtensions.CreateEqualsExpression(outerKey,innerKey), innerSourceParameter))),
outerSourceParameter);

secondaryExpansion = Expression.Call(
Expand Down Expand Up @@ -415,7 +415,7 @@ outerKey is NewArrayExpression newArrayExpression
})
.Aggregate((l, r) => Expression.AndAlso(l, r))
: Expression.NotEqual(outerKey, Expression.Constant(null, outerKey.Type)),
Infrastructure.ExpressionExtensions.BuildEqualsExpression(outerKey, innerKey));
Infrastructure.ExpressionExtensions.CreateEqualsExpression(outerKey, innerKey));

// Caller should take care of wrapping MaterializeCollectionNavigation
return Expression.Call(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1599,7 +1599,7 @@ static MethodInfo GetThenByMethod(MethodInfo currentGenericMethod)
var innerKeyLambda = RemapLambdaExpression(innerSource, innerKeySelector);

var keyComparison = _removeRedundantNavigationComparisonExpressionVisitor
.Visit(Infrastructure.ExpressionExtensions.BuildEqualsExpression(outerKeyLambda, innerKeyLambda));
.Visit(Infrastructure.ExpressionExtensions.CreateEqualsExpression(outerKeyLambda, innerKeyLambda));

Expression left;
Expression right;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp

var anyLambdaParameter = Expression.Parameter(typeArgument, "p");
var anyLambda = Expression.Lambda(
Infrastructure.ExpressionExtensions.BuildEqualsExpression(anyLambdaParameter, methodCallExpression.Arguments[1]),
Infrastructure.ExpressionExtensions.CreateEqualsExpression(anyLambdaParameter, methodCallExpression.Arguments[1]),
anyLambdaParameter);

return Expression.Call(null, anyMethod, new[] { Visit(methodCallExpression.Arguments[0]), anyLambda });
Expand Down

0 comments on commit f73f511

Please sign in to comment.