Microsoft.EntityFrameworkCore.SQLite is the Entity Framework Core database-provider package for SQLite. It lets an application use EF Core’s common ORM API while the provider generates SQLite-specific implementation code and SQL. Add it as a NuGet PackageReference and restore the project before configuring the application’s DbContext. section 12.2.1
A typical EF Core SQLite setup includes:
- Microsoft.EntityFrameworkCore.SQLite for runtime database-provider support; it also references the main EF Core package. section 12.2.1
- Microsoft.EntityFrameworkCore.Design for shared build-time components used to build the application’s EF Core data model. section 12.2.1
- PackageReference elements in the project file, followed by dotnet restore or automatic IDE restoration. section 12.2.1
Using SQLite as an isolated in-memory database
Tests can create a SqliteConnection with DataSource=:memory:, open it, pass it to DbContextOptionsBuilder<AppDbContext>().UseSqlite(connection), construct the DbContext, and call EnsureCreated(). The database remains available while the connection stays open, allowing multiple DbContext instances to share the same temporary database. This provides fast, isolated tests for services that depend on EF Core’s DbContext without requiring a real database. section 36.4 section 36.5
Listing 12.1 Installing EF Core in an ASP.NET Core application
<Project Sdk="Microsoft.NET.Sdk.Web">
<PropertyGroup>
<TargetFramework>net7.0</TargetFramework> #1
<Nullable>enable</Nullable>
<ImplicitUsings>enable</ImplicitUsings>
</PropertyGroup>
<ItemGroup>
<PackageReference #2
Include="Microsoft.EntityFrameworkCore.SQLite" #2
Version="7.0.0" /> #2
<PackageReference #3
Include="Microsoft.EntityFrameworkCore.Design" #3
Version="7.0.0" > #3
<IncludeAssets>runtime; build; native; contentfiles; #4
Analyzers; buildtransitive</IncludeAssets> #4
<PrivateAssets>all</PrivateAssets> #4
</PackageReference>
</ItemGroup>
See the project-file recipe with Microsoft.EntityFrameworkCore.SQLite and Microsoft.EntityFrameworkCore.Design PackageReference entries, including the .NET 7 target and version 7.0.0 packages. section 12.2.1
