1. No Parameter: If you do not pass the parameter then it creates the database in your LocalDb with a name that matches your {Namespace}.{Context class name}.
  2. Name: If you pass "Name" parameter then it creates database in the LocalDb using that name.
  3. Connection String Name: If you pass connection string name of app.config or web.config then it will create the database as per a connection string.

Database Initialization Strategies in Code-First

  1. CreateDatabaseIfNotExists: This is default initializer.
  2. DropCreateDatabaseIfModelChanges: This initializer drops an existing database and creates a new database, if your model classes have been changed.
  3. DropCreateDatabaseAlways: This initializer drops an existing database every time you run the application, irrespective of whether your model classes have changed or not.
  4. Custom DB Initializer: You can also create your own custom initializer.
public class SchoolDBContext : DbContext
{
	public SchoolDBContext(): base("SchoolDBConnectionString")
	{
		Database.SetInitializer<SchoolDBContext>(new CreateDatabaseIfNotExists<SchoolDBContext>());
		//Database.SetInitializer<SchoolDBContext>(new DropCreateDatabaseIfModelChanges<SchoolDBContext>());
		//Database.SetInitializer<SchoolDBContext>(new DropCreateDatabaseAlways<SchoolDBContext>());
		//Database.SetInitializer<SchoolDBContext>(new SchoolDBInitializer());
	}
}
public class SchoolDBInitializer : DropCreateDatabaseAlways<SchoolDBContext>
{
	protected override void Seed(SchoolDBContext context)
	{
		base.Seed(context);
	}
}

Seed Database

public class SchoolDBInitializer : DropCreateDatabaseAlways<SchoolDBContext>
{
    protected override void Seed(SchoolDBContext context)
    {
        var defaultStandards = new List<Standard>
        {
            new Standard {StandardName = "Standard 1", Description = "First Standard"},
            new Standard {StandardName = "Standard 2", Description = "Second Standard"},
            new Standard {StandardName = "Standard 3", Description = "Third Standard"}
        };
        foreach (var std in defaultStandards)
            context.Standards.Add(std);
        base.Seed(context);
    }
}

Inheritance Strategy