public static FixtureLoader DropCreateDatabaseDoNotEnsureLocalDB <TContext>(TContext context) where TContext : DbContext { context.Database.Delete(); context.Database.Create(); var loader = new FixtureLoader(); loader.RegisterService <DbContext>(context); loader.RegisterService <TContext>(context); return(loader); }
public void InitializeDatabase(TContext context) { if (null == context) { throw new ArgumentNullException("context"); } // make sure we run internal code EnsureLoadedForContext new CreateDatabaseIfNotExists <TContext>(); // apply strategy switch (strat) { case Strategy.DropCreateDatabaseAlways: context.Database.Delete(); context.Database.Create(); break; case Strategy.CreateDatabaseIfNotExists: context.Database.CreateIfNotExists(); break; case Strategy.AppendFixtures: break; default: throw new NotImplementedException(strat.ToString()); } // register context as DbContext as well as as specific implementation loader.RegisterService <TContext>(context); loader.RegisterService <DbContext>(context); // load fixtures foreach (var f in queuedFixtures) { loader.Add(f); } loader.Load(); context.SaveChanges(); }