servicestack ormlite sqlite DateTime getting TimeZone adjustment on insert

懵懂的女人 提交于 2019-12-10 18:36:11

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!