How to seed data using EntityFramework Code first Migrations How to seed data using EntityFramework Code first Migrations asp.net asp.net

How to seed data using EntityFramework Code first Migrations


The intro post shows how to seed datahttp://blogs.msdn.com/b/adonet/archive/2011/11/29/code-first-migrations-beta-1-no-magic-walkthrough.aspx

Seed data: Override the Seed method in this class to add seed data. - The Seed method will be called after migrating to the latest version. - You can use the DbContext.AddOrUpdate() helper extension method to avoid creating duplicate seed data. E.g.

myContext.AddOrUpdate(c => c.FullName,  new Customer { FullName = "Andrew Peters", CustomerNumber = 123 },);