Skip to content

Instantly share code, notes, and snippets.

Last active December 20, 2018 20:59
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
public class ProductsDbContextFactory : IDesignTimeDbContextFactory<ProductsDbContext>
public ProductsDbContext CreateDbContext(string[] args)
// Build config
IConfiguration config = new ConfigurationBuilder()
.SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "../EfDesignDemo"))
// Get connection string
var optionsBuilder = new DbContextOptionsBuilder<ProductsDbContext>();
var connectionString = config.GetConnectionString(nameof(ProductsDbContext));
optionsBuilder.UseSqlServer(connectionString, b => b.MigrationsAssembly("EfDesignDemo.EF.Design"));
return new ProductsDbContext(optionsBuilder.Options);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment