DbMigrationsConfiguration<TContext>.Seed(TContext) Method


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

protected virtual void Seed (TContext context);
abstract member Seed : 'Context -> unit
override this.Seed : 'Context -> unit
Protected Overridable Sub Seed (context As 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.

Applies to