Skip to content
This repository has been archived by the owner on Dec 29, 2020. It is now read-only.

Using SQLite

TrevorPilley edited this page Sep 18, 2014 · 3 revisions

Version Support

MicroLite is built to work with any version of SQLite from 3.7 onwards but requires System.Data.SQLite to be installed as the .NET framework does not ship a native provider for SQLite.

Installing the Provider

Install the System.Data.SQLite.Core nuget package:

Install-Package System.Data.SQLite.Core

Register the Provider

Add the section to your app.config/web.config so that the .NET framework knows about the System.Data.SQLite provider:

<system.data>
    <DbProviderFactories>
        <remove invariant="System.Data.SQLite" />
        <add name="SQLite Data Provider"
             invariant="System.Data.SQLite"
             description=".Net Framework Data Provider for SQLite"
             type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite, Version=1.0.92.0, Culture=neutral, PublicKeyToken=db937bc2d44ff139" />
    </DbProviderFactories>
</system.data>

Make sure that the version specified matches the version you have installed or you will get an exception thrown by the .NET runtime at startup when it tries to resolve the assembly.

Connection String

Add a named connection string for your Database specifying the provider name.

<connectionStrings>
    <add name="SQLiteTest"
         connectionString="Data Source=C:\MyApp\SQLiteTest.db3;Version=3;"
         providerName="System.Data.SQLite" />
</connectionStrings>

Configuring the Connection

Create a session factory using the ForSQLiteConnection extension method supplying the name of the connection string you added to the app.config/web.config.

using MicroLite;
using MicroLite.Configuration;

static void Main(string[] args)
{
    var sessionFactory = Configure
        .Fluently()
        .ForSQLiteConnection("SQLiteTest")
        .CreateSessionFactory();

    ...
}

Supported Identifier Strategies

MicroLite supports the following Identifier Strategies for SQLite:

  • Assigned
  • DbGenerated (using auto increment columns)

Additional Notes

  • SQLite does not support table schemas/namespaces so do not specify a schema name in either attribute or convention based mapping.

See the Getting Started guide for further details on using MicroLite.