ProductsDbContextFactory2
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
public class ProductsDbContextFactory : IDesignTimeDbContextFactory<ProductsDbContext> | |
{ | |
public ProductsDbContext CreateDbContext(string[] args) | |
{ | |
// Build config | |
IConfiguration config = new ConfigurationBuilder() | |
.SetBasePath(Path.Combine(Directory.GetCurrentDirectory(), "../EfDesignDemo")) | |
.AddJsonFile("appsettings.json") | |
.Build(); | |
// 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