-
Notifications
You must be signed in to change notification settings - Fork 3.1k
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
SQLite : Datetime equality comparison not working (in memory) #9071
Comments
Probably the second query is being evaluated on client. There seem to be some mismatch between the format of how values being stored and how parameters are being created. This may be fixed in latest dev due to self-contained type mapping. |
Was the data inserted using EF Core? If not, it may be in an incompatible format. |
No, the data was inserted by reading a sql script before like this: |
The date is inserted this way : '2017-08-19 00:00' . When I query the item without the equal clause on the date, and then I looked at my item specifically, the date is correctly resolved by EF in memory, the day is 19, month 8, year 2017 and the kind is unspecified. |
DateTime maps to TEXT in SQLite. |
Ok, I tried setting in the sql script '2017-08-19 00:00:00.000000' but it's still not finding it when comparing through ==.. Am I doing it wrong ? |
Yep, this is by design. You need to normalize coerced values (e.g. Guid, DateTime, TimeSpan, etc.) for equality comparisons to work with EF. |
Hmm, manually updating the value should have worked... |
No this is not working, I thought I missed a zero at first, but here's the new test I made to be sure:
Maybe I'm missing something... |
Ah, |
Now the question is: Do we want to switch to padding in 2.0? The built-in SQLite function |
On the other hand, the built-in function |
Thank you, it's working with the 2017-08-21 00:00:00 format, the == comparison retrieves the item now. |
@bricelam - Is there anything actionable on our side here? or should we close it as question? |
I've thought about it, and I think the format we have is probably ideal. If you don't have fractional seconds, the format is compatible with Unless someone disagrees, we can close it. |
It's fine for me as long as I know the right format for my scripts :) many thanks to you two !! |
Why was text chosen instead of long for sqlite dates? |
@jjxtra Precision and readability |
Precision I don't get, it still takes 8 bytes for a DateTime object in memory. Converting to text converts those 8 bytes to text and does not add any precision, just wasted chars, separators, etc. |
My testing in #15019 showed that milliseconds would be lost (and that was just TimeSpan, not DateTime). You are free to add a value conversion if you want: modelBuilder.Entity<MyEntity>().Property(e => e.DateTimeProperty)
.HasConversion(ToJulianDay, FromJulianDay); |
Ah, just noticed you asked about long, not double. Answer for that: SQLite only has helper functions for working with datetime values in text and Julian day floating-point values, not long/ticks |
When comparing exact dates in memory with the sqlite provider, it returns no result:
targets.Count is zero.
But this works and returns one item:
I use Microsoft.EntityFrameworkCore.Sqlite 1.1.2.
The text was updated successfully, but these errors were encountered: