Skip to main content

So you want to use Sqlite with EF 6?

You know about normal SQL databases and wanna start playing around with SQLite and have a rough understanding what SQLite is. For working with it you desire to use EF from the start on.
And you want to use the "Database First" Approach and create your model the sqlite database.

Thats how I wanted to do it. Unfortunately, using DB-first approach with sqlite is very tricky and volatile. I managed to do it... only to find that 2 months later my Visual Studio wasnt able to do the same thing again because the "Data Provider" inside my visual studio had forgotten the installed sqlite... and i needed to do the procedure again.

so my actual suggestion is.... if you want to use SQLite with EF then.... don't. 
Seriously.

For now, for small applications I need a local DB started to use Dapper together with SQLite instead and use Code-First. Its really much easier. If you follow the steps in this excellent article during reading you will have a working ORM solution with a running SQL database in under 5 minutes.

With that suggestion and warning out of the way and you still want to use EF together with SQLite...

Then here is your cookbook.

(This at least worked for me after many failed attempts)


A)
Create your VS solution (I still use VS2013); open Nuget Manager, search for and add:

System.Data.SQLite (x86/x64) Version 1.0.103

(I had troubles with other versions).
Ignore all other things you find on this topic on the web.


Install

SQLite/SQL Server Compact Toolbox


then install
sqlite-netFx451-setup-bundle-x86-2013-1.0.103.0.exe

Change the target framework for your projects to 4.5.1 in the "Properties" of the project in your soluion

B)
Download and install "DB Browser for SQLite"
I use version 3.9.0

C)
Open DB Browser for SQLite and create a new database and save it. Lets call it Db.sqlite

D)
Add the newly created database to your visual studio project (via Add>Existing Item...);
You might want to actually add a copy of the original Db.sqlite....

E)
now add a new "ADO.NET Entity Data Model" object to your project. Click "EF Designer from data..." go to "New Connection", under "Data source:" press "Change", and select System.Data.SQLite Database File; connect to your DB.sqlite and you are ready to go


Comments