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

SqlServer Query: Use correct return type for DATE/TIMEFROMPARTS functions #28904

Merged
merged 1 commit into from
Aug 27, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -114,8 +114,8 @@ public SqlServerFromPartsFunctionTranslator(
arguments.Skip(1),
nullable: true,
argumentsPropagateNullability: arguments.Skip(1).Select(_ => true),
DateFromPartsMethodInfo.ReturnType,
_typeMappingSource.FindMapping(DateFromPartsMethodInfo.ReturnType, value.ReturnType));
method.ReturnType,
_typeMappingSource.FindMapping(method.ReturnType, value.ReturnType));
}

return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1133,13 +1133,28 @@ await AssertCount(
async,
ss => ss.Set<Order>(),
ss => ss.Set<Order>(),
c => new TimeSpan(23, 59, 0) > EF.Functions.TimeFromParts(23, 59, 59, c.OrderID % 60, 2),
c => new TimeSpan(23, 59, 0) > new TimeSpan(23, 59, 59, c.OrderID % 60));
c => new TimeSpan(23, 59, 0) > EF.Functions.TimeFromParts(23, 59, 59, c.OrderID % 60, 3),
c => new TimeSpan(23, 59, 0) > new TimeSpan(0, 23, 59, 59, c.OrderID % 60));

AssertSql(
@"SELECT COUNT(*)
FROM [Orders] AS [o]
WHERE '23:59:00' > TIMEFROMPARTS(23, 59, 59, [o].[OrderID] % 60, 2)");
WHERE '23:59:00' > TIMEFROMPARTS(23, 59, 59, [o].[OrderID] % 60, 3)");
}

[ConditionalTheory]
[MemberData(nameof(IsAsyncData))]
public virtual async Task TimeFromParts_select(bool async)
{
await AssertQueryScalar(
async,
ss => ss.Set<Order>()
.Select(o => EF.Functions.TimeFromParts(23, 59, 59, o.OrderID % 60, 3)),
ss => ss.Set<Order>().Select(o => new TimeSpan(0, 23, 59, 59, o.OrderID % 60)));

AssertSql(
@"SELECT TIMEFROMPARTS(23, 59, 59, [o].[OrderID] % 60, 3)
FROM [Orders] AS [o]");
}

[ConditionalTheory]
Expand Down