Entity Framework in SQLite
What is Entity Framework in SQLite?
SQLite is a software library that implements a self-contained, serverless, zero-configuration, transactional SQL database engine.
It is the most widely deployed SQL database engine, and the source code for SQLite is in the public domain.
Two major NuGet packages support SQLite:
- Microsoft.EntityFrameworkCore.Sqlite
- Devart.Data.SQLite.encore
Microsoft.EntityFrameworkCore.Sqlite
Microsoft.EntityFrameworkCore.SQLite database provider allows Entity Framework Core to be used with SQLite. The provider is maintained as part of the Entity Framework Core Project.
How to Use Microsoft.EntityFrameworkCore.SQLite Provider
- The first step is to install Microsoft to use the SQLite database provider.EntityFrameworkCore.Sqlite NuGet package. Let's consider a simple model which contains three entities.
- In EF Core, the DbContext has a virtual method called onConfiguring which will get called internally by EF Core, and it will also pass in an optionsBuilder instance. You can use that optionsBuilder to configure options for the DbContext.
- The optionsBuilder has the UseSqlite method; it expects a connection string as a parameter. Once you have a model, you can use migrations to create a database.
Limitations
The SQLite provider has some migrations limitations, and mostly these limitations are not EF Core specific but underlying SQLite database engine.
- The SQLite provider does not support schemas and Sequences.
- The SQLite database engine does not support the following schema operations supported by most other relational databases.
- AddForeignKey
- AddPrimaryKey
- AddUniqueConstraint
- AlterColumn
- DropColumn
- DropForeignKey
- DropPrimaryKey
- DropUniqueConstrain
- RenameColumn
Devart.Data.SQLite.EFCore
Devart.Data.SQLite.encore is an Entity Framework Core provider created by Devart.
How to Use Devart.Data.SQLite.EFCore Provider
To use Devart.Data.SQLite.EFCore provider, the first step is to install the Devart.Data.SQLite.EFCore NuGet package.