C
C#2y ago
barcode

✅ EF Core Seeders

How do I handle seeders in EF Core? Is there a way to split seeders away from migrations? Currently .HasData creates the insert in the migration
13 Replies
barcode
barcodeOP2y ago
Is there any better way?
Johnny Rage
Johnny Rage2y ago
What is your version of EFCore?
Jayy
Jayy2y ago
I recently wrote a service to do this, i ripped the data out of our migrations I used this to do it on api startup
Jayy
Jayy2y ago
Extensions.Hosting.AsyncInitialization 1.0.0
A simple helper to perform async application initialization for the generic host in .NET Core 2.1 or higher.
barcode
barcodeOP2y ago
7.0 ty gonna check it out
Johnny Rage
Johnny Rage2y ago
Then look for docs, there should be method Seed()
barcode
barcodeOP2y ago
Data Seeding - EF Core
Using data seeding to populate a database with an initial set of data using Entity Framework Core
barcode
barcodeOP2y ago
I read this and it's not what I'm looking for it puts it in migrations
Johnny Rage
Johnny Rage2y ago
No, there should be another way
Johnny Rage
Johnny Rage2y ago
Stack Overflow
How to seed data in .NET Core 6 with Entity Framework?
I know how to seed data to a database with old .NET 5.0 in startup.cs file using my Seeder class with a Seed() method creating some initial data. public void Configure(IApplicationBuilder app,
Johnny Rage
Johnny Rage2y ago
@barcode
Jayy
Jayy2y ago
Yes this is what i was describing above using AsyncInitialization But you have to write it urself
Accord
Accord2y ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server