Wolfgang.DbContextBuilder-Core-EF9 0.8.1

Prefix Reserved
dotnet add package Wolfgang.DbContextBuilder-Core-EF9 --version 0.8.1
                    
NuGet\Install-Package Wolfgang.DbContextBuilder-Core-EF9 -Version 0.8.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Wolfgang.DbContextBuilder-Core-EF9" Version="0.8.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Wolfgang.DbContextBuilder-Core-EF9" Version="0.8.1" />
                    
Directory.Packages.props
<PackageReference Include="Wolfgang.DbContextBuilder-Core-EF9" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Wolfgang.DbContextBuilder-Core-EF9 --version 0.8.1
                    
#r "nuget: Wolfgang.DbContextBuilder-Core-EF9, 0.8.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Wolfgang.DbContextBuilder-Core-EF9@0.8.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Wolfgang.DbContextBuilder-Core-EF9&version=0.8.1
                    
Install as a Cake Addin
#tool nuget:?package=Wolfgang.DbContextBuilder-Core-EF9&version=0.8.1
                    
Install as a Cake Tool

DbContextBuilder

Uses the Builder pattern to create Entity Framework Core and classic Entity Framework DbContext instances using an in-memory database for testing purposes. With DbContextBuilder, you can easily set up a DbContext with predefined data, making it ideal for unit tests and integration tests without having to rely on an actual database whose data can be changed or deleted over time.

NuGet NuGet downloads PR build Release License: MIT .NET GitHub


📦 Installation

DbContextBuilder ships as a family of packages — install the one that matches your EF flavor:

Package EF flavor Notes
Wolfgang.DbContextBuilder-Core EF Core 6 Currently pins EF Core 6 ([6.0.36, 7.0.0)). EF Core 7-10 consumers should install the matching -Core-EF7/8/9/10 package below.
Wolfgang.DbContextBuilder-Core-EF6 EF Core 6 Pins EF Core 6 for projects on the LTS 6.x line.
Wolfgang.DbContextBuilder-Core-EF7 EF Core 7 Pins EF Core 7.
Wolfgang.DbContextBuilder-Core-EF8 EF Core 8 Pins EF Core 8 (LTS).
Wolfgang.DbContextBuilder-Core-EF9 EF Core 9 Pins EF Core 9.
Wolfgang.DbContextBuilder-Core-EF10 EF Core 10 Pins EF Core 10.
Wolfgang.DbContextBuilder-EF6 Classic EF 6 (non-Core) For applications still on System.Data.Entity / EF 6.x.

Random-data and shared add-on packages (install alongside your EF Core package):

Package Role
Wolfgang.DbContextBuilder.AutoFixture AutoFixture-backed random data. Adds .UseAutoFixture() for SeedWithRandom.
Wolfgang.DbContextBuilder.Bogus Bogus-backed random data (realistic fake values). Adds .UseBogus().
Wolfgang.DbContextBuilder.Abstractions Shared ICreateRandomEntities abstraction, EF-Core-version-independent. Referenced transitively by the provider packages.
# Pick whichever matches your project's EF version, plus a random-data provider
dotnet add package Wolfgang.DbContextBuilder-Core-EF8
dotnet add package Wolfgang.DbContextBuilder.AutoFixture   # or .Bogus

🎯 Supported Frameworks

Each package targets the .NET runtimes its EF version requires:

Package Target Frameworks
Wolfgang.DbContextBuilder-Core net10.0
Wolfgang.DbContextBuilder-Core-EF6 net6.0
Wolfgang.DbContextBuilder-Core-EF7 net7.0
Wolfgang.DbContextBuilder-Core-EF8 net8.0
Wolfgang.DbContextBuilder-Core-EF9 net9.0
Wolfgang.DbContextBuilder-Core-EF10 net10.0
Wolfgang.DbContextBuilder-EF6 (classic) net462; net47; net471; net472; net48; net481
Wolfgang.DbContextBuilder.Abstractions netstandard2.0; net10.0
Wolfgang.DbContextBuilder.AutoFixture net6.0; net7.0; net8.0; net9.0; net10.0
Wolfgang.DbContextBuilder.Bogus net6.0; net7.0; net8.0; net9.0; net10.0

📄 License

This project is licensed under the MIT License. See the LICENSE file for details.


📚 Documentation


✨ Features

  • In-memory DbContext for tests. By default, DbContextBuilder uses the EF Core InMemory provider. Pass your own DbContextOptionsBuilder to switch to SQLite in-memory or any other provider.

  • Seed with your own data using .SeedWith<T>(...) — accepts an IEnumerable<T> or a params T[].

  • Seed with random data using .SeedWithRandom<T>(count) to simulate real-world databases where additional rows beyond your test fixtures exist. Choose a random-data provider — .UseAutoFixture() (the Wolfgang.DbContextBuilder.AutoFixture package) or .UseBogus() (Wolfgang.DbContextBuilder.Bogus) — or plug in your own ICreateRandomEntities via .UseCustomRandomEntityCreator(...).

  • Composable. Chain SeedWith, SeedWithRandom, and provider options in any order, then call .BuildAsync() to materialize the DbContext.


🚀 Usage

// Create a DbContext with seeded random data and your test data
var context = await new DbContextBuilder<YourDbContext>()
    // Pick a random-data provider (or .UseBogus()) so SeedWithRandom has a generator
    .UseAutoFixture()

    // Seed with 10 random entities
    .SeedWithRandom<YourEntity>(10)

    // Seed with specific data
    .SeedWith
    (
        new YourEntity
        {
            Id = 1,
            Name = "Test Entity"
        }
    )

    // Seed with 5 more random entities
    .SeedWithRandom<YourEntity>(5)

    // Build the DbContext instance
    .BuildAsync();

// Use the context in your tests
var sut = new YourService(context);

📖 API surface

The Core package exposes a small, focused surface. The full reference is on the docs site; the most-used entry points are:

Type / Method What it does
DbContextBuilder<T> The builder itself. Construct one per test, chain configuration, then call BuildAsync().
.UseInMemory() EF Core InMemory provider. Fastest, ignores relational constraints.
.UseSqlite() SQLite in-memory provider. Enforces relational constraints.
.UseSqliteForMsSqlServer() SQLite in-memory with a SQL-Server compatibility layer that flattens schema-qualified table names and rewrites SQL-Server-specific default-value SQL.
.UseAutoFixture() Plug AutoFixture in as the random-entity generator (used by SeedWithRandom). Requires the Wolfgang.DbContextBuilder.AutoFixture package.
.UseBogus() Plug Bogus in as the random-entity generator (realistic fake values). Requires the Wolfgang.DbContextBuilder.Bogus package.
.UseCustomRandomEntityCreator(creator) Plug in any ICreateRandomEntities implementation.
.UseDbContextOptionsBuilder(opts) Bring your own DbContextOptionsBuilder<T> to override the provider entirely.
.UseSeedProfile(profile) Apply a reusable ISeedProfile<T> — a named bundle of seed data shareable across tests. Multiple profiles accumulate.
.UseDiagnosticOutput(writeLine) Route EF Core logs (and a one-line seed summary) to a sink such as testOutputHelper.WriteLine.
.SeedWith<TEntity>(...) Seed specific rows. Accepts IEnumerable<T> or params T[].
.SeedWithRandom<TEntity>(count, [func]) Seed N random rows (requires a random-data provider). Optional func mutates each generated entity.
.BuildAsync() Materialize the DbContext. The builder owns the underlying connection; dispose the context with await using.
SqliteModelCustomizer Customization hooks for the SQLite-for-SQL-Server mode: OverrideTableRenaming, OverrideDefaultValueHandling, OverrideComputedValueHandling, OverrideManyToManyTableHandling, DefaultValueMap.
ICreateDbContext / ICreateRandomEntities Extension points for plugging in your own provider or random-entity generator.
Product Compatible and additional computed target framework versions.
.NET net9.0 is compatible.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  net10.0 was computed.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (2)

Showing the top 2 NuGet packages that depend on Wolfgang.DbContextBuilder-Core-EF9:

Package Downloads
Wolfgang.DbContextBuilder.AutoFixture

AutoFixture-backed random test-data generation for Wolfgang.DbContextBuilder. Adds UseAutoFixture() so SeedWithRandom<T>() fills entities with random values. Pick the package whose .NET target matches your EF Core version.

Wolfgang.DbContextBuilder.Bogus

Bogus-backed random test-data generation for Wolfgang.DbContextBuilder. Adds UseBogus() so SeedWithRandom<T>() fills entities with realistic-looking fake values. Pick the package whose .NET target matches your EF Core version.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
0.8.1 1,791 8/22/2026
0.8.0 184 6/26/2026
0.7.0 118 6/22/2026
0.6.1 134 5/9/2026
0.6.0 116 5/4/2026
0.3.3 504 12/10/2025
0.3.2 243 10/30/2025
0.3.1 239 10/30/2025
0.3.0 251 10/29/2025