带有Entity Framework的SQLite DATETIME列

我有一个现有的SQLite数据库,我想在Entity Framework中使用它。 然而,SQLite奇怪的类型系统意味着你甚至可以

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

日期存储为Unix时间整数。 我的模型类是由Visual Studio自动生成的,那么如何告诉代码生成器正确处理这些日期而不是让应用程序抛出

字符串未被识别为有效的DateTime。

启动时的exception?

您必须将连接字符串更改为类似的内容

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

您可以在Server Explorer//Modify Connection/Advanced更改这些设置Server Explorer//Modify Connection/Advanced ,但更改其中的设置将不会传播到您的App.config连接字符串。