John Mathison
John Mathison

Reputation: 914

ASP MVC 5 EF6 Migrations & Seed

We are developing a large ASP MVC web application EF6 Code First (100+ entities) and we have some doubts about migrations.

I have seen a few different approaches: - Seed data in the Seed function of Migrations Configuration, with a AddOrUpdate command, but I have seen in some places that this is a bad approach. - Seed data in a Add-Migration using Sql("INSERT INTO....");

Thanks in advance.

Upvotes: 0

Views: 224

Answers (1)

Steve Greene
Steve Greene

Reputation: 12324

I usually start development just using the initializers. There is a seed method specifically for initializers that only runs when the database is created which is ideal for security and lookup tables. (Migration initializers run with every update-database).

When I get to the point where I don't want to lose other data, I switch to migrations. As you mention, these can accumulate so I use Chris's technique to roll them up before deployment.

You should also be aware of the issues working with migrations in a team environment.

Upvotes: 0

Related Questions