Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

SQLite DATETIME column with Entity Framework

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?

like image 689
marczellm Avatar asked Jun 19 '14 20:06

marczellm


1 Answers

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.

like image 65
marczellm Avatar answered Oct 18 '22 23:10

marczellm