Skip to content

Commit

Permalink
Make SetProperty accept a non-expression lambda directly
Browse files Browse the repository at this point in the history
  • Loading branch information
roji committed Sep 19, 2022
1 parent 0ccad8e commit edfbcba
Show file tree
Hide file tree
Showing 2 changed files with 7 additions and 11 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -1152,7 +1152,7 @@ static Expression PruneOwnedIncludes(IncludeExpression includeExpression)
/// <param name="setPropertyCalls">
/// The lambda expression containing
/// <see
/// cref="SetPropertyCalls{TSource}.SetProperty{TProperty}(Expression{Func{TSource, TProperty}}, Expression{Func{TSource, TProperty}})" />
/// cref="SetPropertyCalls{TSource}.SetProperty{TProperty}(Func{TSource, TProperty}, Func{TSource, TProperty})" />
/// statements.
/// </param>
/// <returns>The non query after translation.</returns>
Expand Down Expand Up @@ -1370,11 +1370,7 @@ when methodCallExpression.Method.IsGenericMethod
&& methodCallExpression.Method.DeclaringType!.IsGenericType
&& methodCallExpression.Method.DeclaringType.GetGenericTypeDefinition() == typeof(SetPropertyCalls<>):

list.Add((
methodCallExpression.Arguments[0].UnwrapLambdaFromQuote(),
methodCallExpression.Arguments[1] is UnaryExpression { NodeType: ExpressionType.Quote } quoteExpression
? (LambdaExpression)quoteExpression.Operand
: methodCallExpression.Arguments[1]));
list.Add(((LambdaExpression)methodCallExpression.Arguments[0], methodCallExpression.Arguments[1]));

PopulateSetPropertyCalls(methodCallExpression.Object!, list, parameter);

Expand Down
10 changes: 5 additions & 5 deletions src/EFCore.Relational/Query/SetPropertyCalls.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,12 +34,12 @@ private SetPropertyCalls()
/// <param name="valueExpression">A value expression.</param>
/// <returns>
/// The same instance so that multiple calls to
/// <see cref="SetPropertyCalls{TSource}.SetProperty{TProperty}(Expression{Func{TSource, TProperty}}, Expression{Func{TSource, TProperty}})" />
/// <see cref="SetPropertyCalls{TSource}.SetProperty{TProperty}(Func{TSource, TProperty}, Func{TSource, TProperty})" />
/// can be chained.
/// </returns>
public SetPropertyCalls<TSource> SetProperty<TProperty>(
Expression<Func<TSource, TProperty>> propertyExpression,
Expression<Func<TSource, TProperty>> valueExpression)
Func<TSource, TProperty> propertyExpression,
Func<TSource, TProperty> valueExpression)
=> throw new InvalidOperationException(RelationalStrings.SetPropertyMethodInvoked);

/// <summary>
Expand All @@ -50,10 +50,10 @@ public SetPropertyCalls<TSource> SetProperty<TProperty>(
/// <param name="valueExpression">A value expression.</param>
/// <returns>
/// The same instance so that multiple calls to
/// <see cref="SetPropertyCalls{TSource}.SetProperty{TProperty}(Expression{Func{TSource, TProperty}}, TProperty)" /> can be chained.
/// <see cref="SetPropertyCalls{TSource}.SetProperty{TProperty}(Func{TSource, TProperty}, TProperty)" /> can be chained.
/// </returns>
public SetPropertyCalls<TSource> SetProperty<TProperty>(
Expression<Func<TSource, TProperty>> propertyExpression,
Func<TSource, TProperty> propertyExpression,
TProperty valueExpression)
=> throw new InvalidOperationException(RelationalStrings.SetPropertyMethodInvoked);

Expand Down

0 comments on commit edfbcba

Please sign in to comment.