Share via


Database.SetInitializer<TContext> 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 msdn.com/data/ef.]

Sets 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)

Syntax

'Declaration
Public Shared Sub SetInitializer(Of TContext As DbContext) ( _
    strategy As IDatabaseInitializer(Of TContext) _
)
'Usage
Dim strategy As IDatabaseInitializer(Of TContext)

Database.SetInitializer(strategy)
public static void SetInitializer<TContext>(
    IDatabaseInitializer<TContext> strategy
)
where TContext : DbContext
public:
generic<typename TContext>
where TContext : DbContext 
static void SetInitializer(
    IDatabaseInitializer<TContext>^ strategy
)
static member SetInitializer : 
        strategy:IDatabaseInitializer<'TContext> -> unit   when 'TContext : DbContext
JScript does not support generic types and methods.

Type Parameters

  • TContext
    The type of the context.

Parameters

See Also

Reference

Database Class

System.Data.Entity Namespace