EntityFrameworkCore.Seeder 1.0.4

There is a newer prerelease version of this package available.
See the version list below for details.
dotnet add package EntityFrameworkCore.Seeder --version 1.0.4
                    
NuGet\Install-Package EntityFrameworkCore.Seeder -Version 1.0.4
                    
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="EntityFrameworkCore.Seeder" Version="1.0.4" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="EntityFrameworkCore.Seeder" Version="1.0.4" />
                    
Directory.Packages.props
<PackageReference Include="EntityFrameworkCore.Seeder" />
                    
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 EntityFrameworkCore.Seeder --version 1.0.4
                    
#r "nuget: EntityFrameworkCore.Seeder, 1.0.4"
                    
#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 EntityFrameworkCore.Seeder@1.0.4
                    
#: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=EntityFrameworkCore.Seeder&version=1.0.4
                    
Install as a Cake Addin
#tool nuget:?package=EntityFrameworkCore.Seeder&version=1.0.4
                    
Install as a Cake Tool

Dotnet Ef Seeder

Banner

This package defines a pattern to register and execute seeders to populate a database with test data. Find the package here

Those coming from the Laravel world, the api is highly inspired by what is proposed in Laravel.

Installation

The installation is pretty straight forward, enter the following command

dotnet add package EntityFrameworkCore.Seeder

Usage

The package is built to suit any .net application. It works by isolation the seeder of a specific entity. To generate fake data, we built a wrapper on to of Bogus. The rules are simple:

  • Create a factory class for your entity
  • Create a seeder for your entity
  • Register the dependencies through ASP.NET Core DI Container
  • Run the dotnet run --seed command

Let's walk through those steps.

1. Create a factory class

In the sample application, we created a Todo entity. We create a factory class by extending the base Factory which forces us to define a set of rules that will help generating fake data.

public class TodoFactory : Factory<Todo>
{
    protected override Faker<Todo> BuildRules()
    {
        return new Faker<Todo>()
            .RuleFor(t => t.Title, f => f.Lorem.Sentence())
            .RuleFor(t => t.IsCompleted, f => f.Random.Bool());
    }
}

2. Create a seeder

A seeder is responsible of the database transaction that will add the relevant entities to the database. It supports dependency injection, so we can inject our dbContext to manipulate the database.

public class TodoSeeder(AppDbContext appDbContext) : ISeeder
{
    private readonly AppDbContext _appDbContext = appDbContext;

    public async Task SeedAsync()
    {
        var todos = new TodoFactory().Generate(10);
        await _appDbContext.AddRangeAsync(todos);
        await _appDbContext.SaveChangesAsync();
    }
}

3. Register the dependencies

The next step is to register the required dependencies in the DI Container. In the service section, do the following:

builder.Services.ConfigureSeedersEngine();
builder.Services.AddSeeder<TodoSeeder>();

Alternatively, we can register seeders from an assembly using the extension method AddSeedersFromAssembly, so that the framework automatically scans that assembly to register each seeder.

Next, we map the --seed and -s command to the pipeline as follows.

bool appliedAny = await app.MapSeedCommandsAsync(args)

This method takes as parameter the args array, and returns wether or not a seeder was applied. We can opt to stop the application after the process, or continue. The choice is ours.

4. Run the command

The last step is to run a command that will apply our seeders. The command is the following:

dotnet run --seed

This command runs sequentially all the registered seeders, no matter the order. We can run a specific seeder by specifying its name, or run multiple ones by separating names by spaces.

dotnet run --seed <FirstSeederName> <SecondSeederName> ...

This ensures that the seeders are applied in the correct order.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  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

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.5-alpha 78 2/25/2026
1.0.4 90 2/14/2026
1.0.2-alpha.0.11 45 2/14/2026
1.0.2-alpha.0.9 48 2/14/2026
1.0.1 360 7/29/2024
1.0.0 309 7/29/2024