Advertisement
Guest User

Untitled

a guest
Mar 25th, 2019
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.90 KB | None | 0 0
  1. using Microsoft.AspNetCore;
  2. using Microsoft.AspNetCore.Hosting;
  3. using Microsoft.EntityFrameworkCore;
  4. using Microsoft.Extensions.DependencyInjection;
  5. using System.Threading.Tasks;
  6. using MyApp.Data;
  7.  
  8. namespace MyApp
  9. {
  10. public class Program
  11. {
  12. public static async Task Main(string[] args)
  13. {
  14. var webHost = CreateWebHostBuilder(args).Build();
  15.  
  16. // create a new scope
  17. using (var scope = webHost.Services.CreateScope())
  18. {
  19. // Get the dbcontext instance
  20. var dbContext = scope.ServiceProvider.GetRequiredService<ApplicationDbContext>();
  21.  
  22. // do the migration async
  23. await dbContext.Database.MigrateAsync();
  24. }
  25.  
  26. // Run the web host and start accepting requests
  27. // there's an async overload, so we may as well use it
  28. await webHost.RunAsync();
  29. }
  30.  
  31. public static IWebHostBuilder CreateWebHostBuilder(string[] args)
  32. {
  33. return WebHost.CreateDefaultBuilder(args).UseStartup<Startup>();
  34. }
  35. }
  36. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement