-
Notifications
You must be signed in to change notification settings - Fork 3.2k
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
Translate DateOnly.FromDateTime #30708
Comments
DateOnly is not supported by default with EF Core 7 - maybe you can use my package: https://www.nuget.org/packages/ErikEJ.EntityFrameworkCore.SqlServer.DateOnlyTimeOnly |
@ErikEJ The problem is I'm using your package This is my configuring method (the connection string is injected). protected override void OnConfiguring(DbContextOptionsBuilder builder)
{
builder.UseSqlServer(opt=> opt.UseDateOnlyTimeOnly())
.EnableServiceProviderCaching()
#if DEBUG
.EnableSensitiveDataLogging()
.EnableDetailedErrors()
.EnableThreadSafetyChecks();
#endif
} |
Note: we're lacking this translation in the new 8.0 EF support as well. |
@DrkWzrd ah, cool. So you found a bug, I will look into a fix. |
@DrkWzrd This has been fixed and an updated package version 7.0.3 has been published to Nuget |
@ErikEJ any interest in submitting the PR for here as well? :) |
@roji happy to, if you could just confirm that my fix makes sense...? |
Yep - LGTM (just see https://github.com/ErikEJ/EFCore.SqlServer.DateOnlyTimeOnly/pull/11/files#r1171412466). |
@ErikEJ This weekend I will have time to test it, thanks! This should be a warning about the DateTime-> DateOnly conversion too, I don't know if that it's included. |
@ErikEJ Works like a charm. This should be included in EF8 (with the other conversions missing) |
Thanks! "Other conversions missing" - not sure what you mean by that? |
Nothing, my fault, I was thinking the inverse conversion (DateOnly->DateTime) was not included, but it works by default. Thank you for your effort. ;) |
Is this expected in any of the EFCore 8 previews? |
As noted above, I might make a PR some time. @jonsamwell |
That would be very much appreciated @ErikEJ |
When using
DateOnly.FromDateTime
in some element of a query, it breaks because is not translated to a cast function in SQL.Include your code
This fragment of code (inside a
DbContext
):Include stack traces
Produces this exception:
Include provider and version information
EF Core version: 7.0.5
Database provider: Microsoft.EntityFrameworkCore.SqlServer 7.0.5
Target framework: net7.0
Operating system: Windows 10 x64 Pro
IDE: VS2022 17.5.4
The text was updated successfully, but these errors were encountered: