Skip to content

Instantly share code, notes, and snippets.

@kristofclaes
Created June 29, 2012 11:11
Show Gist options
  • Save kristofclaes/3017384 to your computer and use it in GitHub Desktop.
Save kristofclaes/3017384 to your computer and use it in GitHub Desktop.
public void InitializeDatabase(TContext context)
{
RuntimeFailureMethods.Requires((object) context != null, (string) null, "context != null");
bool flag;
using (new TransactionScope(TransactionScopeOption.Suppress))
{
flag = context.Database.Exists();
}
if (flag)
{
if (!context.Database.CompatibleWithModel(false))
{
throw System.Data.Entity.Resources.Error.DatabaseInitializationStrategy_ModelMismatch((object) context.GetType().Name);
}
}
else
{
context.Database.Create();
this.Seed(context);
context.SaveChanges();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment