Skip to content

Instantly share code, notes, and snippets.

@joewashington75
Created March 25, 2020 20:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save joewashington75/53d2c42da8e10b7aa4a3b7a98976a531 to your computer and use it in GitHub Desktop.
Save joewashington75/53d2c42da8e10b7aa4a3b7a98976a531 to your computer and use it in GitHub Desktop.
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