Share via

DbMigrationsConfiguration<TContext>.Seed Method

[This page is specific to the Entity Framework version 6. The latest version is available as the 'Entity Framework' NuGet package. For more information about Entity Framework, see]

Runs after upgrading to the latest migration to allow seed data to be updated.

Namespace:  System.Data.Entity.Migrations
Assembly:  EntityFramework (in EntityFramework.dll)


Protected Overridable Sub Seed ( _
    context As TContext _
Dim context As TContext

protected virtual void Seed(
    TContext context
virtual void Seed(
    TContext context
abstract Seed : 
        context:'TContext -> unit  
override Seed : 
        context:'TContext -> unit
protected function Seed(
    context : TContext


  • context
    Type: TContext
    Context to be used for updating seed data.


Note that the database may already contain seed data when this method runs. This means that implementations of this method must check whether or not seed data is present and/or up-to-date and then only make changes if necessary and in a non-destructive way. The AddOrUpdate<TEntity>(IDbSet<TEntity>, TEntity[]) can be used to help with this, but for seeding large amounts of data it may be necessary to do less granular checks if performance is an issue. If the MigrateDatabaseToLatestVersion<TContext, TMigrationsConfiguration> database initializer is being used, then this method will be called each time that the initializer runs. If one of the DropCreateDatabaseAlways<TContext>, DropCreateDatabaseIfModelChanges<TContext>, or CreateDatabaseIfNotExists<TContext> initializers is being used, then this method will not be called and the Seed method defined in the initializer should be used instead.

See Also


DbMigrationsConfiguration<TContext> Class

System.Data.Entity.Migrations Namespace