Zylvian
.NET 9 - EF Core + Aspire - Database seeding
I've been looking into different ways to seed our database, and there are a lot of conflicting information.
I have a .NET Aspire project, with a BackendService and a MigrationService. I want to seed a bunch of test data into the database if it's not present. I want to do this through EF and not write SQL scripts.
The EF recommendation is using UseAsyncSeeding (as well as UseSeeding?):
https://learn.microsoft.com/en-us/ef/core/modeling/data-seeding#configuration-options-useseeding-and-useasyncseeding-methods
The .NET Aspire docs simply have this:
https://learn.microsoft.com/en-us/ef/core/modeling/data-seeding#configuration-options-useseeding-and-useasyncseeding-methods
I would like for the logic to be seperated from the BackendService, and potentially be an extra worker service that simply adds data to the database, from entities like
SessionEntity
.
Any good repos with examples on how to properly do the seeding? The EF recommendation seems extremely wordy in it's implementation, and I'd like for it to be easy to add to a list of entites you want to seed.5 replies