DbConfiguration.SetDatabaseInitializer<TContext> Method (IDatabaseInitializer<TContext>)

 

Call this method from the constructor of a class derived from DbConfiguration to set the database initializer to use for the given context type. The database initializer is called when a the given DbContext type is used to access a database for the first time. The default strategy for Code First contexts is an instance of CreateDatabaseIfNotExists<TContext>.

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

protected internal void SetDatabaseInitializer<TContext>(
	IDatabaseInitializer<TContext> initializer
)
where TContext : DbContext

Parameters

initializer
Type: System.Data.Entity.IDatabaseInitializer<TContext>

The initializer to use, or null to disable initialization for the given context type.

Type Parameters

TContext

The type of the context.

Calling this method is equivalent to calling SetInitializer<TContext>. This method is provided as a convenient and discoverable way to add configuration to the Entity Framework. Internally it works in the same way as using AddDependencyResolver to add an appropriate resolver for IDatabaseInitializer<TContext>. This means that, if desired, the same functionality can be achieved using a custom resolver or a resolver backed by an Inversion-of-Control container.