marczellm
marczellm

Reputation: 1336

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?

Upvotes: 5

Views: 6299

Answers (1)

marczellm
marczellm

Reputation: 1336

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.

Upvotes: 6

Related Questions