liveBook · Manning

Microsoft.EntityFrameworkCore.SQLite

As explained in ASP.NET Core in Action, 3e

Microsoft.EntityFrameworkCore.SQLite is the NuGet package that supplies SQLite database-provider integration for Entity Framework Core.

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

How ASP.NET Core in Action, 3e covers it

How deep it goes
Explains provider installation and in-memory configuration steps, but stops short of detailed SQLite-specific SQL behavior.
Examples
Uses a .NET 7 project file and a SqliteConnection configured with DataSource=:memory: for DbContext tests.
What it assumes
Assumes a .NET project and basic EF Core DbContext knowledge while teaching package installation and SQLite test setup explicitly.
What you can do after
Operate/configure EF Core with SQLite and create isolated DbContext tests using an open in-memory SqliteConnection.
How it connects
Connects Entity Framework Core, DbContext, NuGet, SQLite in-memory databases, and ASP.NET Core integration testing.

Related concepts

This explainer was generated by Manning's knowledge graph from the text of ASP.NET Core in Action, 3e. The section links point to the parts of the book it draws on.