diff --git a/src/EFCore.Jet/Query/ExpressionTranslators/Internal/JetDateTimeMemberTranslator.cs b/src/EFCore.Jet/Query/ExpressionTranslators/Internal/JetDateTimeMemberTranslator.cs index cc5ee73..cfbad5f 100644 --- a/src/EFCore.Jet/Query/ExpressionTranslators/Internal/JetDateTimeMemberTranslator.cs +++ b/src/EFCore.Jet/Query/ExpressionTranslators/Internal/JetDateTimeMemberTranslator.cs @@ -109,7 +109,7 @@ namespace EntityFrameworkCore.Jet.Query.ExpressionTranslators.Internal false, new[] { false }, returnType)), - nameof(DateTime.TimeOfDay) => _sqlExpressionFactory.NullChecked( + nameof(DateTime.TimeOfDay) => TimeSpanNullChecked( instance!, _sqlExpressionFactory.Function( "TIMEVALUE", @@ -135,8 +135,22 @@ namespace EntityFrameworkCore.Jet.Query.ExpressionTranslators.Internal new CaseWhenClause( _sqlExpressionFactory.IsNull(checkSqlExpression), _sqlExpressionFactory.Constant( - null,typeof(string), - checkSqlExpression.TypeMapping)) + null,typeof(DateTime), + notNullSqlExpression.TypeMapping)) + }, + notNullSqlExpression); + + public CaseExpression TimeSpanNullChecked( + SqlExpression checkSqlExpression, + SqlExpression notNullSqlExpression) + => (CaseExpression)_sqlExpressionFactory.Case( + new[] + { + new CaseWhenClause( + _sqlExpressionFactory.IsNull(checkSqlExpression), + _sqlExpressionFactory.Constant( + null,typeof(TimeSpan), + notNullSqlExpression.TypeMapping)) }, notNullSqlExpression); } diff --git a/test/EFCore.Jet.FunctionalTests/Query/GearsOfWarQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/GearsOfWarQueryJetTest.cs index 2ae8a57..2bb1c4a 100644 --- a/test/EFCore.Jet.FunctionalTests/Query/GearsOfWarQueryJetTest.cs +++ b/test/EFCore.Jet.FunctionalTests/Query/GearsOfWarQueryJetTest.cs @@ -5951,11 +5951,9 @@ ORDER BY `g`.`Nickname`, `m`.`Id` await base.Time_of_day_datetimeoffset(isAsync); AssertSql( -""" -SELECT ('HasSoulPatch ' & (`g`.`HasSoulPatch` & '')) & ' HasSoulPatch', ('Rank ' & (`g`.`Rank` & '')) & ' Rank', ('SquadId ' & (`g`.`SquadId` & '')) & ' SquadId', ('Rating ' & IIF((`m`.`Rating` & '') IS NULL, '', (`m`.`Rating` & ''))) & ' Rating', `m`.`Id`, `m`.`CodeName`, `m`.`Rating` -FROM `Gears` AS `g`, -`Missions` AS `m` -ORDER BY `g`.`Nickname`, `m`.`Id` + """ +SELECT TIMEVALUE(`m`.`Timeline`) +FROM `Missions` AS `m` """); } @@ -7515,7 +7513,7 @@ ORDER BY NOT (`w0`.`IsAutomatic`) SELECT `m`.`Id`, `m`.`CodeName`, `m`.`Date`, `m`.`Difficulty`, `m`.`Duration`, `m`.`Rating`, `m`.`Time`, `m`.`Timeline` FROM `Missions` AS `m` -WHERE DATEVALUE(`m`.`Timeline`) >= @__dateTimeOffset_Date_0 +WHERE DATEVALUE(`m`.`Timeline`) >= CDATE(@__dateTimeOffset_Date_0) """); } diff --git a/test/EFCore.Jet.FunctionalTests/Query/NorthwindSelectQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/NorthwindSelectQueryJetTest.cs index cc309b5..23d414d 100644 --- a/test/EFCore.Jet.FunctionalTests/Query/NorthwindSelectQueryJetTest.cs +++ b/test/EFCore.Jet.FunctionalTests/Query/NorthwindSelectQueryJetTest.cs @@ -2304,9 +2304,9 @@ FROM `Orders` AS `o` await base.Select_datetime_TimeOfDay_component(async); AssertSql( - """ -SELECT CONVERT(time, [o].[OrderDate]) -FROM [Orders] AS [o] + """ +SELECT IIF(`o`.`OrderDate` IS NULL, NULL, TIMEVALUE(`o`.`OrderDate`)) +FROM `Orders` AS `o` """); } diff --git a/test/EFCore.Jet.FunctionalTests/Query/NorthwindWhereQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/NorthwindWhereQueryJetTest.cs index 882658f..3548e7a 100644 --- a/test/EFCore.Jet.FunctionalTests/Query/NorthwindWhereQueryJetTest.cs +++ b/test/EFCore.Jet.FunctionalTests/Query/NorthwindWhereQueryJetTest.cs @@ -1832,8 +1832,10 @@ WHERE ( await base.Time_of_day_datetime(isAsync); AssertSql( - $@"SELECT CAST(`o`.`OrderDate` AS time) -FROM `Orders` AS `o`"); + """ +SELECT IIF(`o`.`OrderDate` IS NULL, NULL, TIMEVALUE(`o`.`OrderDate`)) +FROM `Orders` AS `o` +"""); } public override async Task TypeBinary_short_circuit(bool isAsync) diff --git a/test/EFCore.Jet.FunctionalTests/Query/TPCGearsOfWarQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/TPCGearsOfWarQueryJetTest.cs index b39cbed..3410199 100644 --- a/test/EFCore.Jet.FunctionalTests/Query/TPCGearsOfWarQueryJetTest.cs +++ b/test/EFCore.Jet.FunctionalTests/Query/TPCGearsOfWarQueryJetTest.cs @@ -8278,9 +8278,9 @@ ORDER BY `u`.`Nickname`, `m`.`Id` await base.Time_of_day_datetimeoffset(async); AssertSql( -""" -SELECT CONVERT(time, [m].[Timeline]) -FROM [Missions] AS [m] + """ +SELECT TIMEVALUE(`m`.`Timeline`) +FROM `Missions` AS `m` """); } @@ -10308,7 +10308,7 @@ ORDER BY NOT (`w0`.`IsAutomatic`) SELECT `m`.`Id`, `m`.`CodeName`, `m`.`Date`, `m`.`Difficulty`, `m`.`Duration`, `m`.`Rating`, `m`.`Time`, `m`.`Timeline` FROM `Missions` AS `m` -WHERE DATEVALUE(`m`.`Timeline`) >= @__dateTimeOffset_Date_0 +WHERE DATEVALUE(`m`.`Timeline`) >= CDATE(@__dateTimeOffset_Date_0) """); } diff --git a/test/EFCore.Jet.FunctionalTests/Query/TPHInheritanceQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/TPHInheritanceQueryJetTest.cs index f9cc1ee..caf3e84 100644 --- a/test/EFCore.Jet.FunctionalTests/Query/TPHInheritanceQueryJetTest.cs +++ b/test/EFCore.Jet.FunctionalTests/Query/TPHInheritanceQueryJetTest.cs @@ -620,7 +620,7 @@ WHERE 'Kiwi' = `a`.`Discriminator` await base.Setting_foreign_key_to_a_different_type_throws(); AssertSql( -""" + """ SELECT TOP 2 `a`.`Id`, `a`.`CountryId`, `a`.`Discriminator`, `a`.`Name`, `a`.`Species`, `a`.`EagleId`, `a`.`IsFlightless`, `a`.`FoundOn` FROM `Animals` AS `a` WHERE `a`.`Discriminator` = 'Kiwi' diff --git a/test/EFCore.Jet.FunctionalTests/Query/TPTFiltersInheritanceQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/TPTFiltersInheritanceQueryJetTest.cs index a289c68..7ad3a6a 100644 --- a/test/EFCore.Jet.FunctionalTests/Query/TPTFiltersInheritanceQueryJetTest.cs +++ b/test/EFCore.Jet.FunctionalTests/Query/TPTFiltersInheritanceQueryJetTest.cs @@ -179,7 +179,7 @@ WHERE `a`.`CountryId` = 1 await base.Can_use_IgnoreQueryFilters_and_GetDatabaseValues(async); AssertSql( -""" + """ SELECT TOP 2 `a`.`Id`, `a`.`CountryId`, `a`.`Name`, `a`.`Species`, `b`.`EagleId`, `b`.`IsFlightless`, `e`.`Group` FROM (`Animals` AS `a` INNER JOIN `Birds` AS `b` ON `a`.`Id` = `b`.`Id`) diff --git a/test/EFCore.Jet.FunctionalTests/Query/TPTGearsOfWarQueryJetTest.cs b/test/EFCore.Jet.FunctionalTests/Query/TPTGearsOfWarQueryJetTest.cs index 77a5cb3..7b403b6 100644 --- a/test/EFCore.Jet.FunctionalTests/Query/TPTGearsOfWarQueryJetTest.cs +++ b/test/EFCore.Jet.FunctionalTests/Query/TPTGearsOfWarQueryJetTest.cs @@ -6584,9 +6584,9 @@ ORDER BY `g`.`Nickname`, `m`.`Id` await base.Time_of_day_datetimeoffset(async); AssertSql( -""" -SELECT CONVERT(time, [m].[Timeline]) -FROM [Missions] AS [m] + """ +SELECT TIMEVALUE(`m`.`Timeline`) +FROM `Missions` AS `m` """); } @@ -8299,7 +8299,7 @@ ORDER BY NOT (`w0`.`IsAutomatic`) SELECT `m`.`Id`, `m`.`CodeName`, `m`.`Date`, `m`.`Difficulty`, `m`.`Duration`, `m`.`Rating`, `m`.`Time`, `m`.`Timeline` FROM `Missions` AS `m` -WHERE DATEVALUE(`m`.`Timeline`) >= @__dateTimeOffset_Date_0 +WHERE DATEVALUE(`m`.`Timeline`) >= CDATE(@__dateTimeOffset_Date_0) """); }