-
Notifications
You must be signed in to change notification settings - Fork 24
Using SQLite
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.
Install the System.Data.SQLite.Core nuget package:
Install-Package System.Data.SQLite.Core
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.
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>
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();
...
}
MicroLite supports the following Identifier Strategies for SQLite:
- Assigned
- DbGenerated (using auto increment columns)
- 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.