Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using Microsoft.AspNetCore;
- using Microsoft.AspNetCore.Hosting;
- using Microsoft.EntityFrameworkCore;
- using Microsoft.Extensions.DependencyInjection;
- using System.Threading.Tasks;
- using MyApp.Data;
- namespace MyApp
- {
- public class Program
- {
- public static async Task Main(string[] args)
- {
- var webHost = CreateWebHostBuilder(args).Build();
- // create a new scope
- using (var scope = webHost.Services.CreateScope())
- {
- // Get the dbcontext instance
- var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
- // do the migration async
- await dbContext.Database.MigrateAsync();
- }
- // Run the web host and start accepting requests
- // there's an async overload, so we may as well use it
- await webHost.RunAsync();
- }
- public static IWebHostBuilder CreateWebHostBuilder(string[] args)
- {
- return WebHost.CreateDefaultBuilder(args).UseStartup<Startup>();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement