![]() |
VOOZH | about |
dotnet add package Dosaic.DevTools.Seeding --version 1.2.34
NuGet\Install-Package Dosaic.DevTools.Seeding -Version 1.2.34
<PackageReference Include="Dosaic.DevTools.Seeding" Version="1.2.34" />
<PackageVersion Include="Dosaic.DevTools.Seeding" Version="1.2.34" />Directory.Packages.props
<PackageReference Include="Dosaic.DevTools.Seeding" />Project file
paket add Dosaic.DevTools.Seeding --version 1.2.34
#r "nuget: Dosaic.DevTools.Seeding, 1.2.34"
#:package Dosaic.DevTools.Seeding@1.2.34
#addin nuget:?package=Dosaic.DevTools.Seeding&version=1.2.34Install as a Cake Addin
#tool nuget:?package=Dosaic.DevTools.Seeding&version=1.2.34Install as a Cake Tool
A developer tool for seeding Entity Framework Core databases with realistic fake data. Built on top of Bogus, it introspects your DbContext model, respects foreign key relationships, and fills tables in the correct dependency order — with full control over row counts and relationship cardinality.
Intended for use in local development environments, integration tests, and demo setups.
dotnet add package Dosaic.DevTools.Seeding
OrderLine.CustomerId is synced to match Order.CustomerId)SaveChanges batch size to control memory pressureIFakeDataSetup<T> to customize generated values per entity type; implementations are auto-discovered via assembly scanningFaker rules for primitive types (e.g. always generate valid Guid or a currency-formatted decimal)| Type | Description |
|---|---|
EfFakeDataSeeder |
Executes the seeding operation against a DbContext |
EfFakeDataSeederConfig |
Fluent configuration builder for the seeder |
FakeData |
Wrapper around Bogus Faker<T> with auto-discovery of IFakeDataSetup<T> implementations |
FakeDataConfig |
Configuration for FakeData (locale, strict mode, global type rules) |
IFakeDataSetup<T> |
Interface for declaring per-entity Bogus rules |
Seed all entity types in the model with the default count (10 rows each):
await using var context = new MyDbContext();
var config = EfFakeDataSeederConfig.For(context);
var seeder = new EfFakeDataSeeder(config);
await seeder.SeedAsync(CancellationToken.None);
var config = EfFakeDataSeederConfig.For(context)
.WithTotalCount<Customer>(50) // seed exactly 50 customers
.WithTotalCount<Product>(20) // seed exactly 20 products
.WithDefaultCountPerEntityType(5); // all other entity types: 5 rows each
Use WithRelationCount to declare how many dependent rows to create per principal:
// Each customer gets exactly 2 orders
var config = EfFakeDataSeederConfig.For(context)
.WithTotalCount<Customer>(5)
.WithRelationCount<Order>(x => x.Customer, 2);
// Each order gets between 1 and 10 order lines
var config = EfFakeDataSeederConfig.For(context)
.WithRelationCount<OrderLine>(x => x.Order, min: 1, max: 10);
// Each order gets either 1, 2, or 3 order lines (picked at random)
var config = EfFakeDataSeederConfig.For(context)
.WithRelationCount<Order>(x => x.Customer, 1, 2, 3);
var config = EfFakeDataSeederConfig.For(context)
.WithIgnore<AuditLog>()
.WithIgnore<MigrationHistory>();
By default SaveChangesAsync is called every 200 rows. Adjust to tune memory vs. I/O:
var config = EfFakeDataSeederConfig.For(context)
.WithBatchSize(500);
IFakeDataSetup<T>Implement IFakeDataSetup<T> to attach Bogus rules to a specific entity type. Implementations are discovered automatically from all loaded assemblies — no registration required.
using Bogus;
using Dosaic.Testing.NUnit.Extensions;
public class CustomerFakeDataSetup : IFakeDataSetup<Customer>
{
public void ConfigureRules(Faker<Customer> faker)
{
faker.RuleFor(x => x.Id, f => f.Random.Guid());
faker.RuleFor(x => x.Name, f => f.Name.FullName());
faker.RuleFor(x => x.Email, f => f.Internet.Email());
faker.RuleFor(x => x.State, f => f.PickRandom<CustomerState>());
}
}
public class ProductFakeDataSetup : IFakeDataSetup<Product>
{
public void ConfigureRules(Faker<Product> faker)
{
faker.RuleFor(x => x.Id, f => f.Random.Guid());
faker.RuleFor(x => x.Name, f => f.Commerce.Product());
faker.RuleFor(x => x.Price, f => Math.Round(f.Random.Decimal(1m, 500m), 2));
}
}
FakeData globallyUse FakeData.ConfigureInstance once at application startup to customise locale, strict mode, or primitive type rules:
var fakeDataConfig = new FakeDataConfig
{
Locale = "de",
UseStrictMode = false,
};
fakeDataConfig.AddTypeRule<Guid>(f => f.Random.Guid());
fakeDataConfig.AddTypeRule<decimal>(f => Math.Round(f.Random.Decimal(0m, 1000m), 2));
FakeData.ConfigureInstance(fakeDataConfig);
Pass a custom FakeData instance directly to the config when needed:
var fakeData = new FakeData(fakeDataConfig);
var config = EfFakeDataSeederConfig.For(context, fakeData);
FakeData standaloneFakeData can also be used independently to generate test objects outside of seeding:
var fakeData = FakeData.Instance;
// Generate a single instance
var customer = fakeData.Fake<Customer>();
// Generate with inline customisation
var vipCustomer = fakeData.Fake<Customer>(c => c.State = CustomerState.Active);
// Generate a list
var products = fakeData.Fakes<Product>(10);
// Generate a list with customisation
var orders = fakeData.Fakes<Order>(5, (faker, o) =>
{
o.Date = faker.Date.Recent().ToUniversalTime();
});
// Access the raw Bogus Faker for one-off values
string randomName = fakeData.Faker.Name.FullName();
// 1. Define fake data rules
public class OrderFakeDataSetup : IFakeDataSetup<Order>
{
public void ConfigureRules(Faker<Order> faker)
{
faker.RuleFor(x => x.Id, f => f.Random.Guid());
faker.RuleFor(x => x.Date, f => f.Date.Past().ToUniversalTime());
}
}
// 2. Configure and run the seeder
await using var context = new ShopDbContext();
var config = EfFakeDataSeederConfig.For(context)
.WithTotalCount<Customer>(50)
.WithTotalCount<Product>(100)
.WithRelationCount<Order>(x => x.Customer, min: 1, max: 5)
.WithRelationCount<OrderLine>(x => x.Order, min: 1, max: 10)
.WithIgnore<OutboxMessage>()
.WithBatchSize(500);
var seeder = new EfFakeDataSeeder(config);
await seeder.SeedAsync();
This will:
Customer rows, then 100 Product rowsOrder rows — 1–5 per customer (50–250 orders total)OrderLine rows — 1–10 per order, with OrderLine.CustomerId automatically synced to the parent order's CustomerIdOutboxMessage entirelyEfFakeDataSeederConfig| Method | Default | Description |
|---|---|---|
EfFakeDataSeederConfig.For(context) |
— | Creates a config for the given DbContext using FakeData.Instance |
EfFakeDataSeederConfig.For(context, fakeData) |
— | Creates a config with a custom FakeData instance |
.WithDefaultCountPerEntityType(n) |
10 |
Row count for entity types without an explicit override |
.WithTotalCount<T>(n) |
— | Row count for a specific entity type |
.WithIgnore<T>() |
— | Exclude an entity type from seeding |
.WithRelationCount<T>(nav, count) |
— | Exact number of dependents per principal |
.WithRelationCount<T>(nav, min, max) |
— | Dependents per principal drawn from [min, max] |
.WithRelationCount<T>(nav, params int[]) |
— | Dependents per principal chosen from the given options |
.WithBatchSize(n) |
200 |
Number of entities added before each SaveChangesAsync call |
FakeDataConfig| Property / Method | Default | Description |
|---|---|---|
Locale |
"en" |
Bogus locale string (e.g. "de", "fr") |
UseStrictMode |
false |
Enables Bogus strict mode — every property must have a rule |
.AddTypeRule<T>(Func<Faker, T>) |
— | Global rule applied to all fakers for the given CLR type |
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net10.0 net10.0 is compatible. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
Showing the top 1 NuGet packages that depend on Dosaic.DevTools.Seeding:
| Package | Downloads |
|---|---|
|
Dosaic.Testing.NUnit
A plugin-first dotnet framework for rapidly building anything hosted in the web. |
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.2.34 | 106 | 6/10/2026 |
| 1.2.33 | 112 | 6/2/2026 |
| 1.2.31 | 110 | 5/28/2026 |
| 1.2.30 | 123 | 5/7/2026 |
| 1.2.29 | 118 | 5/5/2026 |
| 1.2.28 | 124 | 4/30/2026 |
| 1.2.27 | 118 | 4/29/2026 |
| 1.2.26 | 108 | 4/29/2026 |
| 1.2.25 | 131 | 4/27/2026 |
| 1.2.24 | 116 | 4/21/2026 |
| 1.2.23 | 121 | 4/14/2026 |
| 1.2.22 | 120 | 4/10/2026 |
| 1.2.21 | 118 | 4/10/2026 |
| 1.2.20 | 121 | 4/10/2026 |
| 1.2.19 | 119 | 4/9/2026 |
| 1.2.18 | 135 | 4/2/2026 |
| 1.2.17 | 114 | 4/1/2026 |
| 1.2.16 | 110 | 4/1/2026 |
| 1.2.15 | 117 | 3/31/2026 |
| 1.2.14 | 121 | 3/30/2026 |