示例#1
0
        private CoffeeBuyersContext PrepareContext()
        {
            var cnnString = Configuration.GetSection("ConnectionStrings:DefaultConnectionString").Value;


            var context = new CoffeeBuyersContext(new DbContextOptionsBuilder().UseSqlServer(cnnString).Options);

            context.Database.Migrate();
            return(context);
        }
示例#2
0
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, CoffeeBuyersContext context)
        {
            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
            }
            else
            {
                app.UseHsts();
            }

            app.UseSwagger().UseSwaggerUI(setup =>
            {
                setup.SwaggerEndpoint("/swagger/v1/swagger.json", "Coffee Buyers");
            });

            app.MigrateDatabase(context);
            app.UseHttpsRedirection();
            app.UseMvc(routes => { routes.MapRoute("default", "{controller=Default}/{action=Swagger}"); });
        }
 public static void MigrateDatabase(this IApplicationBuilder builder, CoffeeBuyersContext context)
 {
     context.Database.Migrate();
 }
 public CoffeeBuyersController(CoffeeBuyersContext context)
 {
     _context = context;
 }