与实体框架的SQLite DATETIME列 [英] SQLite DATETIME column with Entity Framework
问题描述
我有我想在实体框架使用现有的SQLite数据库。然而SQLite的的怪异类型系统意味着你甚至可以
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');
日期存储为的 Unix时间整数。我的模型类是由Visual Studio自动生成的,所以我怎么告诉代码生成正确,而不是处理这些日期的应用程序中扔
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
字符串未被识别为有效的DateTime。
String was not recognized as a valid DateTime.
例外?
推荐答案
您必须更改连接字符串,类似
You have to change your connection string to something like
data source="|DataDirectory|\data.sqlite";datetimeformat=UnixEpoch;datetimekind=Utc
您可以在服务器资源管理器/<更改这些设置,右键单击您的连接和GT; /修改连接/高级
,但更改设置会有的不会传播的您的App.config的连接字符串。
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.
这篇关于与实体框架的SQLite DATETIME列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!