Exemplo n.º 1
0
        static void Main(string[] args)
        {
            var connectionString = args.Any() ?
                                   args[0] :
                                   TableTopDataContextFactory.DefaultConnectionString;

            Console.WriteLine($"Connection string: {connectionString}");

            using (var context = new TableTopDataContextFactory().CreateDbContext(new[] { connectionString }))
            {
                Console.WriteLine("Migrations started.");
                context.Database.Migrate();
                Console.WriteLine("Migrations finished.");

                var dataSeedOrchestrator = new DataSeedOrchestrator(context);

                Console.WriteLine("Seeding preparing.");
                dataSeedOrchestrator.PrepareDatabase();
                Console.WriteLine("Seeding prepared.");

                Console.WriteLine("Seeding started.");
                dataSeedOrchestrator.ApplyAll();
                Console.WriteLine("Seeding finished.");
            }

            Console.WriteLine("All done.");
        }
Exemplo n.º 2
0
        static void Main(string[] args)
        {
            IConfigurationRoot configuration = new ConfigurationBuilder()
                                               .SetBasePath(Directory.GetCurrentDirectory())
                                               .AddJsonFile("app.settings.json")
                                               .Build();
            string ConnectionString = configuration["ConnectionStrings:TestDatabase"];

            var optionsBuilder = new DbContextOptionsBuilder <DataContext>();
            var options        = optionsBuilder.UseSqlServer(ConnectionString).Options;

            using (var context = new DataContext(options))
            {
                DataSeedOrchestrator dataSeedOrchestrator = new DataSeedOrchestrator(context);
                dataSeedOrchestrator.ApplyAll();
            }

            Console.WriteLine("All data were uploaded to MS SQL Server");
        }