-
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
Add DateOnly.ToString / TimeOnly.ToString query mapping for SQL Server #31289
Conversation
@dotnet-policy-service agree |
src/EFCore.SqlServer/Query/Internal/SqlServerDateOnlyMethodTranslator.cs
Outdated
Show resolved
Hide resolved
src/EFCore.SqlServer/Query/Internal/SqlServerObjectToStringTranslator.cs
Show resolved
Hide resolved
@sulton-max please take a look at the failing tests. |
Need help on this Issue - DateOnly standard format Currently I'm having 2 issues
So
I guess because data we are using in How can I solve this ? Tried multiple formats for SQL Lite in if (instance?.Type == typeof(DateOnly)
&& method.Name == nameof(DateOnly.ToString))
{
return _sqlExpressionFactory.Function(
"strftime",
new[] { _sqlExpressionFactory.Constant("%m/%d/%Y"), instance },
nullable: true,
argumentsPropagateNullability: new[] { false, true },
returnType: typeof(string));
} |
src/EFCore.SqlServer/Query/Internal/SqlServerDateOnlyMethodTranslator.cs
Outdated
Show resolved
Hide resolved
@sulton-max please do the same thing for DateOnly/TimeOnly that we already do for DateTime - no more and no less; as @ErikEJ wrote above, there shouldn't be a DateOnly-specific translation with FORMAT, which uses a hard-coded United States date format. See the DateTime tests for ToString to understand how it should work. |
Ok, I removed method translators for @roji I thought about that initially, but had a hard time finding where are |
See Object_to_string_conversion. Note that we cannot assert on the actual results from ToString(); since the translation is a SQL cast, every database has its own string representation when a DateTime (or DateOnly) is cast to a string. This is by design. |
Oh, I see now. Should I add So overall there must be 3 tests right ? ( in 3 overridden versions of |
Yes |
test/EFCore.Specification.Tests/Query/GearsOfWarQueryTestBase.cs
Outdated
Show resolved
Hide resolved
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@sulton-max I pushed a commit that removes the unrelated formatting changes and will merge as soon as the build is green - thanks for your contribution.
FYI it's important to review all your proposed changes before submitting a PR to make sure that nothing unintended slips in (like the above formatting stuff), a PR should ideally change exactly what it's supposed to, nothing more.
@sulton-max You are welcome, congrats on your first contribution to EF Core |
@sulton-max we're always happy to receive contributions and to guide contributors where needed. But it's important for you to tackle tasks that you can overall reasonably accomplish by yourself, otherwise the guidance that we provide requires more time and effort than directly implementing the feature. |
Summary of changes
Added Translator to the list of
SqlServerObjectToStringTranslators
Added base test to
GearsOfWarQueryTestBase
Added overloads of the base test to
GearsOfWarQuerySqlServerTest
,TPCGearsOfWarQuerySqlServerTest
andTPTGearsOfWarQuerySqlServerTest
Fixes Translate DateOnly.ToString() / TimeOnly.ToString() ?? #31035