diff --git a/src/EFCore.SqlServer/Query/Internal/Translators/SqlServerTimeOnlyMethodTranslator.cs b/src/EFCore.SqlServer/Query/Internal/Translators/SqlServerTimeOnlyMethodTranslator.cs index 53e602d74a5..6a9f952c816 100644 --- a/src/EFCore.SqlServer/Query/Internal/Translators/SqlServerTimeOnlyMethodTranslator.cs +++ b/src/EFCore.SqlServer/Query/Internal/Translators/SqlServerTimeOnlyMethodTranslator.cs @@ -64,7 +64,9 @@ public SqlServerTimeOnlyMethodTranslator(ISqlExpressionFactory sqlExpressionFact && instance is null && arguments.Count == 1) { - return _sqlExpressionFactory.Convert(arguments[0], typeof(TimeOnly)); + return arguments[0].Type is typeof(TimeSpan) + ? arguments[0] + : _sqlExpressionFactory.Convert(arguments[0], typeof(TimeOnly)); } if (instance is null) diff --git a/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs b/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs index 2d227cda094..3adb2e9aabf 100644 --- a/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs +++ b/test/EFCore.SqlServer.FunctionalTests/Query/GearsOfWarQuerySqlServerTest.cs @@ -9352,7 +9352,7 @@ public override async Task Where_TimeOnly_FromTimeSpan_compared_to_property(bool """ SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] -WHERE CAST([m].[Duration] AS time) < [m].[Time] +WHERE [m].[Duration] < [m].[Time] """); } @@ -9366,7 +9366,7 @@ public override async Task Where_TimeOnly_FromTimeSpan_compared_to_parameter(boo SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] -WHERE CAST([m].[Duration] AS time) = @__time_0 +WHERE [m].[Duration] = @__time_0 """); } @@ -9378,7 +9378,7 @@ public override async Task Order_by_TimeOnly_FromTimeSpan(bool async) """ SELECT [m].[Id], [m].[BriefingDocument], [m].[BriefingDocumentFileExtension], [m].[CodeName], [m].[Date], [m].[Difficulty], [m].[Duration], [m].[Rating], [m].[Time], [m].[Timeline] FROM [Missions] AS [m] -ORDER BY CAST([m].[Duration] AS time) +ORDER BY [m].[Duration] """); }