Using SQLite with Visual Studio 2013 and Entity Framework

First we need a tool for creating and managing the database.

We use this Firefox AddIn: https://addons.mozilla.org/de/firefox/addon/sqlite-manager/
Create a new database and a table in it. Do not forget to set a primary key.

Install SQLite package:

http://system.data.sqlite.org/index.html/doc/trunk/www/downloads.wiki
And here:

Setups for 32-bit Windows (.NET Framework 4.5.1)

In the Visual Studio project, add this NuGet package:

System.Data.SQLite (x86/x64)
During the install, EF 6.0 will be installed as a prerequisite

Build

Add New Item -> Data => ADO.NET Entity Data Model

EF Designer from Database

This should be available:
System.Data.SQLite Database File (.NET Framework Data Provider for SQLite)

Browse to the DB file and open it

In the “Choose Your Database Objects and Settings” dialog select the table(s)
you want to use

Then you can do something like this:

using (var db = new sqliteEntities())
{
  db.Person.Add(new Person { Name = "Rainer", Age = 51 });
  db.SaveChanges();
}

Leave a Reply