Created
March 25, 2020 20:44
-
-
Save joewashington75/53d2c42da8e10b7aa4a3b7a98976a531 to your computer and use it in GitHub Desktop.
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 EFCoreSeparateProject.Infrastructure; | |
using Microsoft.EntityFrameworkCore; | |
using Microsoft.EntityFrameworkCore.Design; | |
using Microsoft.Extensions.Configuration; | |
using System.IO; | |
namespace EFCoreSeparateProject.Migrations | |
{ | |
public class ExampleDbContextFactory : IDesignTimeDbContextFactory<ExampleDbContext> | |
{ | |
public ExampleDbContext CreateDbContext(string[] args) | |
{ | |
var configuration = new ConfigurationBuilder() | |
.SetBasePath(Directory.GetCurrentDirectory()) | |
.AddJsonFile("appsettings.json", true) | |
.AddEnvironmentVariables() | |
.AddCommandLine(args) | |
.Build(); | |
var optionsBuilder = new DbContextOptionsBuilder<ExampleDbContext>(); | |
optionsBuilder.UseSqlServer(configuration.GetValue<string>("SqlConnectionString"), x => x.MigrationsAssembly("EFCoreSeparateProject.Migrations")); | |
return new ExampleDbContext(optionsBuilder.Options); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment