Seed Data
See original GitHub issueIn EF6, this was accomplished using DbMigrationsConfiguration.Seed()
, but migrations configurations don’t exist in EF7.
- Add
EntityTypeBuilder.SeedData
- Add support for shared table seeding
- Add support for owned types seeding
- Add seed data validation
- Reuse existing code by delegating to
IStateManager
,IEntityMaterializerSource
andSharedTableEntryMap
-
Documentation:https://github.com/aspnet/EntityFramework.Docs/issues/509 -
Add support for navigation seeding:https://github.com/aspnet/EntityFrameworkCore/issues/10000 -
Addhttps://github.com/aspnet/EntityFrameworkCore/issues/9999EntityTypeBuilder.SeedData
sugar that takes an entity and a property bag for shadow properties: -
Perf: batch the operations:https://github.com/aspnet/EntityFrameworkCore/issues/9997 -
Perf: skip optimistic concurrency checks:https://github.com/aspnet/EntityFrameworkCore/issues/9998
Issue Analytics
- State:
- Created 9 years ago
- Reactions:28
- Comments:73 (30 by maintainers)
Top Results From Across the Web
Data Seeding - EF Core
Data seeding is the process of populating a database with an initial set of data. There are several ways this can be accomplished...
Read more >Database seeding
Database seeding is populating a database with an initial set of data. It's common to load seed data such as initial user accounts...
Read more >Applying Seed Data To The Database
Applying seed data to a database refers to the process of inserting initial data into a database, usually when the database is first...
Read more >Seed Data in EF 6 Code-First
Learn how to seed the default or the test data in the database using EF 6 code-first approach.
Read more >Seeding your database - Prisma
This guide describes how to seed your database using Prisma Client and Prisma's integrated seeding functionality. Seeding allows you to consistently ...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
We should be able to add data along with a specific migration. For example, I add a new table and then add some data to it right after the table is created. This is really important for domain data, that mainly changes when some app structure changes. An example is menu records, where I mostly only add a new menu record when I add a new feature. So, it would be great to have some methods to add/change data on the
MigrationBuilder
class.Proposal is to have a Seed.cs file in the Migrations directory (alongside model snapshot etc.). We could scaffold this when the first migration is added:
This is essentially the same as the Seed method on EF6.x. While this approach has it’s issues it seems to work pretty well and we haven’t heard a lot of complaints.
We could also look at some simple Insert/Update/Delete APIs in Migrations. This would give folks a more advanced option that overcomes some of the limitations of Seed():
Of course, data in migrations would be loosely typed since it wouldn’t use the current model.