Skip to content

Commit

Permalink
SqlServer Query: Use correct return type for DATE/TIMEFROMPARTS funct…
Browse files Browse the repository at this point in the history
…ions

Fixes #27853
  • Loading branch information
bricelam committed Aug 27, 2022
1 parent 69912f0 commit 4d2bfc4
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 5 deletions.
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

0 comments on commit 4d2bfc4

Please sign in to comment.