-
Notifications
You must be signed in to change notification settings - Fork 3.4k
Open
Open
Copy link
Milestone
Description
In the below code, DateTime.Now is translated to GETDATE() and DateTime.UtcNow is translated to GETUTCDATE() - these functions return SQL Server's datetime.
Should they use equivalent functions that return datetime2 instead? These are SYSDATETIME() and SYSUTCDATETIME() respectively. The precision and range of datetime2 is a closer (exact?) match to .NET DateTime so it feels like the more faithful translation, but I'm not sure if there are legacy reasons to use the older functions.
I can submit a PR to fix this if it's considered a valid proposal.
efcore/src/EFCore.SqlServer/Query/Internal/SqlServerDateTimeMemberTranslator.cs
Lines 96 to 110 in c8c6c21
| case nameof(DateTime.Now): | |
| return _sqlExpressionFactory.Function( | |
| declaringType == typeof(DateTime) ? "GETDATE" : "SYSDATETIMEOFFSET", | |
| Array.Empty<SqlExpression>(), | |
| nullable: false, | |
| argumentsPropagateNullability: Array.Empty<bool>(), | |
| returnType); | |
| case nameof(DateTime.UtcNow): | |
| var serverTranslation = _sqlExpressionFactory.Function( | |
| declaringType == typeof(DateTime) ? "GETUTCDATE" : "SYSUTCDATETIME", | |
| Array.Empty<SqlExpression>(), | |
| nullable: false, | |
| argumentsPropagateNullability: Array.Empty<bool>(), | |
| returnType); |