问题
It seems that this new version is not handling dates correctly. Please see the below observations:
1) When using the below:
_conn.Create<MyTable>();
And I have a DateTime field in MyTable class, then, it's creating it as BIGINT column inside the SQLite DB.
2) If I change the BIGINT column to a datetime-to match the DateTime definition in MyTable class-any existing rows are read back as 01/01/0001!
3) If I try to save a date value into that datetime field, say, set it to DateTime.Today it's saving it as 30-12-1899. And it doesn't matter what value you try to save. It's always saved as 30-12-1899.
NOTE: I'm using MVVMCross on Android.
T.I.A.
回答1:
There's a long story in the SQLite-net code about how DateTime should be stored.
You can read more about this and find plenty of opinions and links on https://github.com/MvvmCross/MvvmCross/issues/213
As a result of this discussion, the new SQLite port uses StoreDateTimeAsTicks as it's default setting.
Given the weight of opinions from people on the above github issues thread, I'd recommend using the StoreDateTimeAsTicks setting. If there are bugs (as you suggest in 3) then I'd recommend chasing this through with the SQLite-net community - including details about the platform and version you are using.
If you want to change this setting, then you can pass in:
options.StoreDateTimeAsTicks = false
to the SQLite factory.
For more info on options see: https://github.com/MvvmCross/MvvmCross-SQLite/blob/master/Sqlite/Cirrious.MvvmCross.Community.Plugins.Sqlite/BaseClasses.cs#L27
来源:https://stackoverflow.com/questions/21460271/community-sqlite-not-handling-dates-datetimes-correctly