DbConfiguration.SetDatabaseInitializer<TContext> Method

Definition

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>.

protected internal void SetDatabaseInitializer<TContext> (System.Data.Entity.IDatabaseInitializer<TContext> initializer) where TContext : System.Data.Entity.DbContext;
member this.SetDatabaseInitializer : System.Data.Entity.IDatabaseInitializer<'Context (requires 'Context :> System.Data.Entity.DbContext)> -> unit (requires 'Context :> System.Data.Entity.DbContext)
Protected Friend Sub SetDatabaseInitializer(Of TContext As DbContext) (initializer As IDatabaseInitializer(Of TContext))

Type Parameters

TContext

The type of the context.

Parameters

initializer
IDatabaseInitializer<TContext>

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

Remarks

Calling this method is equivalent to calling SetInitializer<TContext>(IDatabaseInitializer<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.

Applies to