IT:AD:Code First:Seeding

Somewhere early, define this:

Database.SetInitializer(new MyInitializer());

This will be a custom implementation of IDatabaseInitializer that enherits from a well-known strategy:

//Invoke *early*, eg from a Boottrapper:
//Database.SetInitializer<GraphContext>(new GraphInitializer());
public class MyInitializer : DropCreateDatabaseIfModelChanges<TestContext>
{
  ...

  protected override void Seed(GraphContext context)
  {
  
    BuildCountryLookup(context);

    //etc
  }
}
  • What's the strategy for handling multiple Initializers (ie, Vendors, each with their own initialization requirements)?
  • /home/skysigal/public_html/data/pages/it/ad/code_first/dbcontext_seeding.txt
  • Last modified: 2023/11/04 22:22
  • by 127.0.0.1