diff --git a/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeAddTranslator.cs b/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeAddTranslator.cs index 9af6bd69053..c827a3812a6 100644 --- a/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeAddTranslator.cs +++ b/src/EFCore.Sqlite.Core/Query/Internal/SqliteDateTimeAddTranslator.cs @@ -84,7 +84,7 @@ public SqliteDateTimeAddTranslator(SqliteSqlExpressionFactory sqlExpressionFacto _sqlExpressionFactory.Convert( _sqlExpressionFactory.Divide( arguments[0], - _sqlExpressionFactory.Constant((double)TimeSpan.TicksPerDay)), + _sqlExpressionFactory.Constant((double)TimeSpan.TicksPerSecond)), typeof(string)), _sqlExpressionFactory.Constant(" seconds")); } diff --git a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindMiscellaneousQuerySqliteTest.cs b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindMiscellaneousQuerySqliteTest.cs index cd15e05344e..9e42026809c 100644 --- a/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindMiscellaneousQuerySqliteTest.cs +++ b/test/EFCore.Sqlite.FunctionalTests/Query/NorthwindMiscellaneousQuerySqliteTest.cs @@ -149,14 +149,15 @@ public override async Task Select_expression_datetime_add_second(bool async) public override async Task Select_expression_datetime_add_ticks(bool async) { - // Add ticks. Issue #25851. - Assert.Equal( - "1996-07-04T00:00:00.0000000", - (await Assert.ThrowsAsync( - () => base.Select_expression_datetime_add_ticks(async))).Actual); + // modifying the original scenario - Sqlite gives inaccurate results for values of granularity less than 1 second + await AssertQuery( + async, + ss => ss.Set().Where(o => o.OrderDate != null) + .Select(o => new Order { OrderDate = o.OrderDate.Value.AddTicks(10 * TimeSpan.TicksPerSecond) }), + e => e.OrderDate); AssertSql( - @"SELECT rtrim(rtrim(strftime('%Y-%m-%d %H:%M:%f', ""o"".""OrderDate"", CAST((10000 / 864000000000) AS TEXT) || ' seconds'), '0'), '.') AS ""OrderDate"" + @"SELECT rtrim(rtrim(strftime('%Y-%m-%d %H:%M:%f', ""o"".""OrderDate"", CAST((100000000 / 10000000) AS TEXT) || ' seconds'), '0'), '.') AS ""OrderDate"" FROM ""Orders"" AS ""o"" WHERE ""o"".""OrderDate"" IS NOT NULL"); }