Skip to content

Commit

Permalink
Remove EF.Default since we are punting for 7.0
Browse files Browse the repository at this point in the history
Current implementation has issues and we're too late in the game to address them with confidence.

See #28660 and #28921
  • Loading branch information
ajcvickers committed Sep 2, 2022
1 parent 3c6b0d3 commit 76ad745
Show file tree
Hide file tree
Showing 8 changed files with 1 addition and 84 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -732,12 +732,6 @@ protected override Expression VisitMethodCall(MethodCallExpression methodCallExp
}
}

// EF.Default
if (methodCallExpression.Method.IsEFDefaultMethod())
{
return new SqlFragmentExpression("DEFAULT");
}

var method = methodCallExpression.Method;
var arguments = methodCallExpression.Arguments;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -227,24 +227,6 @@ protected override Expression VisitBinary(BinaryExpression binaryExpression)
return visitedExpression;
}

/// <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 Expression VisitMethodCall(MethodCallExpression methodCallExpression)
{
// EF.Default
if (methodCallExpression.Method.IsEFDefaultMethod())
{
AddTranslationErrorDetails(SqliteStrings.DefaultNotSupported);
return QueryCompilationContext.NotTranslatedExpression;
}

return base.VisitMethodCall(methodCallExpression);
}

private static Type? GetProviderType(SqlExpression? expression)
=> expression == null
? null
Expand Down
17 changes: 0 additions & 17 deletions src/EFCore/EF.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,6 @@ public static partial class EF
internal static readonly MethodInfo PropertyMethod
= typeof(EF).GetTypeInfo().GetDeclaredMethod(nameof(Property))!;

internal static readonly MethodInfo DefaultMethod
= typeof(EF).GetTypeInfo().GetDeclaredMethod(nameof(Default))!;

/// <summary>
/// This flag is set to <see langword="true" /> when code is being run from a design-time tool, such
/// as "dotnet ef" or one of the Package Manager Console PowerShell commands "Add-Migration", "Update-Database", etc.
Expand Down Expand Up @@ -58,20 +55,6 @@ public static TProperty Property<TProperty>(
[NotParameterized] string propertyName)
=> throw new InvalidOperationException(CoreStrings.PropertyMethodInvoked);

/// <summary>
/// Used set a property to its default value within <see cref="M:RelationalQueryableExtensions.ExecuteUpdate" /> or
/// <see cref="M:RelationalQueryableExtensions.ExecuteUpdateAsync" />.
/// </summary>
/// <remarks>
/// Depending on how the property is configured, this may be <see langword="null" />, or another value defined via
/// <see cref="M:RelationalPropertyBuilderExtensions.HasDefaultValue" /> or similar.
/// </remarks>
/// <typeparam name="T">The type of the property being set.</typeparam>
/// <returns>The default value of the property.</returns>
public static T Default<T>()
// TODO: Update exception message
=> throw new InvalidOperationException(CoreStrings.DefaultMethodInvoked);

/// <summary>
/// Provides CLR methods that get translated to database functions when used in LINQ to Entities queries.
/// Calling these methods in other contexts (e.g. LINQ to Objects) will throw a <see cref="NotSupportedException" />.
Expand Down
13 changes: 0 additions & 13 deletions src/EFCore/Infrastructure/MethodInfoExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -32,17 +32,4 @@ public static bool IsEFPropertyMethod(this MethodInfo methodInfo)
// always true in .NET Native even if methods are the same
|| (methodInfo.Name == nameof(EF.Property)
&& methodInfo.DeclaringType?.FullName == EFTypeName));

/// <summary>
/// Returns <see langword="true" /> if the given method is <see cref="EF.Default{T}" />.
/// </summary>
/// <param name="methodInfo">The method.</param>
/// <returns><see langword="true" /> if the method is <see cref="EF.Default{T}" />; <see langword="false" /> otherwise.</returns>
public static bool IsEFDefaultMethod(this MethodInfo methodInfo)
=> methodInfo.IsGenericMethod
&& (Equals(methodInfo.GetGenericMethodDefinition(), EF.DefaultMethod)
// fallback to string comparison because MethodInfo.Equals is not
// always true in .NET Native even if methods are the same
|| (methodInfo.Name == nameof(EF.DefaultMethod)
&& methodInfo.DeclaringType?.FullName == EFTypeName));
}
3 changes: 1 addition & 2 deletions src/EFCore/Query/EvaluatableExpressionFilter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -81,8 +81,7 @@ public virtual bool IsEvaluatableExpression(Expression expression, IModel model)
|| Equals(method, RandomNextNoArgs)
|| Equals(method, RandomNextOneArg)
|| Equals(method, RandomNextTwoArgs)
|| method.DeclaringType == typeof(DbFunctionsExtensions)
|| method.IsEFDefaultMethod())
|| method.DeclaringType == typeof(DbFunctionsExtensions))
{
return false;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -380,17 +380,6 @@ public virtual Task Update_Where_set_constant(bool async)
rowsAffectedCount: 8,
(b, a) => Assert.All(a, c => Assert.Equal("Updated", c.ContactName)));

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual Task Update_Where_set_default(bool async)
=> AssertUpdate(
async,
ss => ss.Set<Customer>().Where(c => c.CustomerID.StartsWith("F")),
e => e,
s => s.SetProperty(c => c.ContactName, c => EF.Default<string>()),
rowsAffectedCount: 8,
(b, a) => Assert.All(a, c => Assert.Null(c.ContactName)));

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual async Task Update_Where_parameter_set_constant(bool async)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -568,17 +568,6 @@ FROM [Customers] AS [c]
WHERE [c].[CustomerID] LIKE N'F%'");
}

public override async Task Update_Where_set_default(bool async)
{
await base.Update_Where_set_default(async);

AssertExecuteUpdateSql(
@"UPDATE [c]
SET [c].[ContactName] = DEFAULT
FROM [Customers] AS [c]
WHERE [c].[CustomerID] LIKE N'F%'");
}

public override async Task Update_Where_parameter_set_constant(bool async)
{
await base.Update_Where_parameter_set_constant(async);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -550,12 +550,6 @@ public override async Task Update_Where_set_constant(bool async)
WHERE ""c"".""CustomerID"" LIKE 'F%'");
}

public override Task Update_Where_set_default(bool async)
=> AssertTranslationFailed(
RelationalStrings.UnableToTranslateSetProperty(
"c => c.ContactName", "c => EF.Default<string>()", SqliteStrings.DefaultNotSupported),
() => base.Update_Where_set_default(async));

public override async Task Update_Where_parameter_set_constant(bool async)
{
await base.Update_Where_parameter_set_constant(async);
Expand Down

0 comments on commit 76ad745

Please sign in to comment.