public static void Initialize(ReckonDesktopContext context) { int currentVersion = 0; try { if (context.SchemaVersions.Any()) { currentVersion = context.SchemaVersions.Max(x => x.Version); } } catch (Exception ex) { } SPWatcherContextHelper mmSqliteHelper = new SPWatcherContextHelper(); while (currentVersion < RequiredDatabaseVersion) { currentVersion++; foreach (string migration in mmSqliteHelper.Migrations[currentVersion]) { if (!string.IsNullOrEmpty(migration)) { context.Database.ExecuteSqlCommand(migration); } } context.SchemaVersions.Add(new SchemaVersion { Version = currentVersion }); context.SaveChanges(); } }
private static ReckonDesktopContext CreateAndSeedDatabase() { var context = new ReckonDesktopContext(); Initialize(context); return(context); }