SQLite DATETIME column with Entity Framework

ε祈祈猫儿з 提交于 2019-11-28 01:44:52

问题


I have an existing SQLite database that I want to use in Entity Framework. However SQLite's weird type system means you can even

create table temp(temp datetime);
insert into temp values ('whatever');

The dates are stored as Unix time integers. My model classes are autogenerated by Visual Studio, so how do I tell the code generator to handle these dates correctly and not make the application throw

String was not recognized as a valid DateTime.

exceptions on startup?


回答1:


You have to change your connection string to something like

data source="|DataDirectory|\data.sqlite";datetimeformat=UnixEpoch;datetimekind=Utc

You can change these settings in Server Explorer/<right click your connection>/Modify Connection/Advanced, but changing the settings there will not propagate to your App.config connection string.



来源:https://stackoverflow.com/questions/24315887/sqlite-datetime-column-with-entity-framework

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