问题
i'm trying ormlite. i'm finding that when i insert an object with a DateTime property, it is getting -8:00 (my timezone is +8) applied by ormlite. It should be inserted with literally what the time is. in my case it is already UTC.
however reading the values out of ormlite, the +8 is not getting re-applied.
is this a known bug?
thanks
回答1:
I think it is inserted in UTC kind. After reading DateTime from database try to apply .ToLocalTime()
回答2:
So your question looks related to this pull request: https://github.com/kojoru/ServiceStack.OrmLite/commit/d3f63ccd40f945b8dc03fd627ad49a895d4277de
If you check the code in SqlServerOrmLiteDialectProvider.cs
, it looks like setting SqlServerOrmLiteDialectProvider.EnsureUtc(true)
would fix your problem.
var dialect = new SqlServerOrmLiteDialectProvider();
dialect.EnsureUtc(true);
var factory = new OrmLiteConnectionFactory(cnnStr, dialect);
var connection = factory.Open();
Check EnsureUtcTest.cs
for an example. Old question, I know, but I hope that helps.
来源:https://stackoverflow.com/questions/14250715/servicestack-ormlite-sqlite-datetime-getting-timezone-adjustment-on-insert