Sqlite

Registering Sqlite Provider

Sqlite has a .NET provider named System.Data.Sqlite. You need to first install it in MyProject.Web:

Install-Package System.Data.SQLite.Core -Project MyProject.Web

If you didn’t install this provider in GAC/machine.config before, or don’t want to install it there, you need to register it in web.config file:

  1. <configuration>
  2. // ...
  3. <system.data>
  4. <DbProviderFactories>
  5. <remove invariant="System.Data.SQLite"/>
  6. <add name="SQLite Data Provider"
  7. invariant="System.Data.SQLite"
  8. description=".Net Framework Data Provider for SQLite"
  9. type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite"/>
  10. </DbProviderFactories>
  11. </system.data>
  12. // ...

Setting Connection Strings

Next step is to replace connection strings for databases you want to use with Sqlite:

  1. <connectionStrings>
  2. <add name="Default" connectionString=
  3. "Data Source=|DataDirectory|Serene_Default_v1.sqlite;"
  4. providerName="System.Data.Sqlite" />
  5. <add name="Northwind" connectionString=
  6. "Data Source=|DataDirectory|Serene_Northwind_v1.sqlite;"
  7. providerName="System.Data.Sqlite" />
  8. </connectionStrings>

Applying Sqlite Changes to Serene

Sqlite provider has been added recently, so if you already have an application, you’ll need to get latest version of SiteInitialization.Migrations.cs from latest template / github repository to get Sqlite support.

Provider name must be System.Data.Sqlite for Serenity to auto-detect dialect. Read notes above to override default dialect.

I’m not sure why, but while FluentMigrator creates Northwind database for Sqlite first time, it takes some time.

Configuring Code Generator

Sergen doesn’t have reference to Sqlite provider, so if you want to use it to generate code, you must also register this provider with it.

Sergen.exe is an exe file, so you can’t add a NuGet reference to it. We need to register this provider in application config file.

It is also possible to register the provider in GAC/machine.config and skip this step completely.

Locate Sergen.exe, which is under a folder like packages/Serenity.CodeGenerator.1.8.6/tools and create a file named Sergen.exe.config next to it with contents below:

  1. <?xml version="1.0" encoding="utf-8" ?>
  2. <configuration>
  3. <system.data>
  4. <DbProviderFactories>
  5. <remove invariant="System.Data.SQLite"/>
  6. <add name="SQLite Data Provider"
  7. invariant="System.Data.SQLite"
  8. description=".Net Framework Data Provider for SQLite"
  9. type="System.Data.SQLite.SQLiteFactory, System.Data.SQLite"/>
  10. </DbProviderFactories>
  11. </system.data>
  12. <appSettings>
  13. <add key="LoadProviderDLLs" value="Sqlite.Data.dll"/>
  14. </appSettings>
  15. </configuration>

Also copy System.Data.Sqlite.dll and its x86 and x64 folders under bin directory to same folder where Sergen.exe resides. Now Sergen will be able to generate code for your Sqlite tables.