Beispiel #1
0
        public static void Main(string[] args)
        {
            Console.WriteLine(@"Migrating database...");
            var migrator = new DbMigrator(new Configuration());
            Console.WriteLine(@"Connection: " + GetConnectionString(migrator));

            var migrations = migrator.GetPendingMigrations().ToList();

            if (!migrations.Any()) {
                Console.WriteLine(@"No pending migrations.");
            } else {
                foreach (var migration in migrations) {
                    Console.WriteLine(migration);
                    migrator.Update(migration);
                }
            }

            if (args.Contains("--seed")) {
                Console.WriteLine(@"Seeding the database...");
                var context = new EntityContext();

                DatabaseSeeder.Seed(context);

                context.SaveChanges();
            } else {
                Console.WriteLine(@"No seeding required.");
            }
            Console.WriteLine(@"Migration done.");
        }
 internal static void Seed(EntityContext context)
 {
     context.AddOrUpdate(new Person {
         Id = 1,
         Fornavn = "Geir",
         Etternavn = "Sagberg"
     });
 }