EntityFrameworkCore.Seeder
1.0.4
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
<PackageReference Include="EntityFrameworkCore.Seeder" Version="1.0.4" />
<PackageVersion Include="EntityFrameworkCore.Seeder" Version="1.0.4" />
<PackageReference Include="EntityFrameworkCore.Seeder" />
paket add EntityFrameworkCore.Seeder --version 1.0.4
#r "nuget: EntityFrameworkCore.Seeder, 1.0.4"
#:package EntityFrameworkCore.Seeder@1.0.4
#addin nuget:?package=EntityFrameworkCore.Seeder&version=1.0.4
#tool nuget:?package=EntityFrameworkCore.Seeder&version=1.0.4
Dotnet Ef Seeder
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 --seedcommand
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 | Versions 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. |
-
net10.0
- Bogus (>= 35.6.0)
- Microsoft.AspNetCore.Http.Abstractions (>= 2.2.0)
- Microsoft.Extensions.DependencyInjection.Abstractions (>= 10.0.3)
- Microsoft.Extensions.Logging.Abstractions (>= 10.0.3)
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 |