Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

EF.Default doesn't work for value types #28921

Closed
ajcvickers opened this issue Aug 30, 2022 · 1 comment
Closed

EF.Default doesn't work for value types #28921

ajcvickers opened this issue Aug 30, 2022 · 1 comment

Comments

@ajcvickers
Copy link
Member

Value type can be nullable or not-nullable; doesn't work either way.

await context.Set<Post>()
    .ExecuteUpdateAsync(
        setPropertyCalls => setPropertyCalls
            .SetProperty(post => post.PublishedOn, post => EF.Default<DateTime>()));

See ResetPostPublishedOnToDefault in https://github.com/dotnet/EntityFramework.Docs/blob/main/samples/core/Miscellaneous/NewInEFCore7/ExecuteUpdateSample.cs

warn: 8/30/2022 18:22:48.438 RelationalEventId.QueryPossibleUnintendedUseOfEqualsWarning[20501] (Microsoft.EntityFrameworkCore.Query)
      Possible unintended use of method 'Equals' for arguments 'p.PublishedOn' and 'DEFAULT' of different types in a query. This comparison will always return false.
Unhandled exception. System.InvalidOperationException: The LINQ expression 'DbSet<FeaturedPost>()
    .ExecuteUpdate(setPropertyCalls => setPropertyCalls.SetProperty<DateTime>(
        propertyExpression: post => post.PublishedOn,
        valueExpression: post => EF.Default<DateTime>()))' could not be translated. Additional information: The following 'SetProperty' failed to translate: 'SetProperty(post => post.PublishedOn, post => EF.Default<DateTime>())'.  See https://go.microsoft.com/fwlink/?linkid=2101038 for more information.
   at Microsoft.EntityFrameworkCore.Query.RelationalQueryableMethodTranslatingExpressionVisitor.VisitMethodCall(MethodCallExpression methodCallExpression)
   at System.Linq.Expressions.MethodCallExpression.Accept(ExpressionVisitor visitor)
   at System.Linq.Expressions.ExpressionVisitor.Visit(Expression node)
   at Microsoft.EntityFrameworkCore.Query.QueryCompilationContext.CreateQueryExecutor[TResult](Expression query)
   at Microsoft.EntityFrameworkCore.Storage.Database.CompileQuery[TResult](Expression query, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.CompileQueryCore[TResult](IDatabase database, Expression query, IModel model, Boolean async)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.<>c__DisplayClass12_0`1.<ExecuteAsync>b__0()
   at Microsoft.EntityFrameworkCore.Query.Internal.CompiledQueryCache.GetOrAddQuery[TResult](Object cacheKey, Func`1 compiler)
   at Microsoft.EntityFrameworkCore.Query.Internal.QueryCompiler.ExecuteAsync[TResult](Expression query, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.Query.Internal.EntityQueryProvider.ExecuteAsync[TResult](Expression expression, CancellationToken cancellationToken)
   at Microsoft.EntityFrameworkCore.RelationalQueryableExtensions.ExecuteUpdateAsync[TSource](IQueryable`1 source, Expression`1 setPropertyCalls, CancellationToken cancellationToken)
   at NewInEfCore7.ExecuteUpdateSample.ResetPostPublishedOnToDefault[TContext]() in C:\github\EntityFramework.Docs\samples\core\Miscellaneous\NewInEFCore7\ExecuteUpdateSample.cs:line 182
   at NewInEfCore7.ExecuteUpdateSample.ResetPostPublishedOnToDefault[TContext]() in C:\github\EntityFramework.Docs\samples\core\Miscellaneous\NewInEFCore7\ExecuteUpdateSample.cs:line 191
   at NewInEfCore7.ExecuteUpdateSample.ExecuteUpdateTest[TContext]() in C:\github\EntityFramework.Docs\samples\core\Miscellaneous\NewInEFCore7\ExecuteUpdateSample.cs:line 59
   at NewInEfCore7.ExecuteUpdateSample.ExecuteUpdateTest[TContext]() in C:\github\EntityFramework.Docs\samples\core\Miscellaneous\NewInEFCore7\ExecuteUpdateSample.cs:line 61
   at Program.Main() in C:\github\EntityFramework.Docs\samples\core\Miscellaneous\NewInEFCore7\Program.cs:line 18
   at Program.<Main>()
@ajcvickers ajcvickers added this to the Backlog milestone Sep 2, 2022
ajcvickers added a commit that referenced this issue Sep 2, 2022
Current implementation has issues and we're too late in the game to address them with confidence.

See #28660 and #28921
smitpatel added a commit that referenced this issue Sep 2, 2022
@smitpatel smitpatel added the closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. label Sep 3, 2022
@ajcvickers ajcvickers removed closed-fixed The issue has been fixed and is/will be included in the release indicated by the issue milestone. consider-for-next-release labels Oct 20, 2022
@ajcvickers
Copy link
Member Author

Now part of #28660.

@ajcvickers ajcvickers closed this as not planned Won't fix, can't repro, duplicate, stale Oct 20, 2022
@ajcvickers ajcvickers removed this from the Backlog milestone Oct 26, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants