question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

In EF6, this was accomplished using DbMigrationsConfiguration.Seed(), but migrations configurations don’t exist in EF7.

Issue Analytics

  • State:closed
  • Created 9 years ago
  • Reactions:28
  • Comments:73 (30 by maintainers)

github_iconTop GitHub Comments

9reactions
giggiocommented, Dec 12, 2014

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.

9reactions
rowanmillercommented, Oct 9, 2014

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:

public class BloggingContextSeedData : DatabaseSeedData<BloggingContext>
{
    public override void Seed(BloggingContext context)
    { 
    }
}

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():

  • Removes the need to write AddOrUpdate code since the data is inserted once during the migration (and presumably deleted during the down).
  • Removes the need to update the Seed code whenever the model changes (since it is applied at a well known point in time of the schema.

Of course, data in migrations would be loosely typed since it wouldn’t use the current model.

Read more comments on GitHub >

github_iconTop 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 >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found