Last active
February 11, 2019 09:39
-
-
Save ZacharyCouchman/c0287e08d280299a3148c93f72b9e4a2 to your computer and use it in GitHub Desktop.
Adding the below line into the ConfigureServices method of the Startup.cs file will call EF migrations to run on app startup.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
using Microsoft.EntityFrameworkCore; | |
... | |
public void ConfigureServices(IServiceCollection services) | |
{ | |
// Add other services here | |
// Add the database context to the services collection for dependency injection | |
services.AddDbContext<MyDatabaseContext>(options => | |
options.UseSqlServer(Configuration.GetConnectionString("DatabaseConnectionString"))); | |
// Get the database context and apply the migrations | |
var context = services.BuildServiceProvider().GetService<MyDatabaseContext>(); | |
context.Database.Migrate(); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment