Created
June 18, 2021 10:13
-
-
Save manoj-choudhari-git/27d3b95f93caad86ebe3c57de404266c to your computer and use it in GitHub Desktop.
.NET Core - Entity Framework Core - IDesignTimeDbContextFactory Implementation
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 CampContextFactory : IDesignTimeDbContextFactory | |
{ | |
public CampContext CreateDbContext(string[] args) | |
{ | |
var configuration = new ConfigurationBuilder() | |
.SetBasePath(Directory.GetCurrentDirectory()) | |
.AddJsonFile("appsettings.json") | |
.Build(); | |
var dbContextBuilder = new DbContextOptionsBuilder(); | |
var connectionString = configuration | |
.GetConnectionString("SqlConnectionString"); | |
dbContextBuilder.UseSqlServer(connectionString); | |
return new CampContext(dbContextBuilder.Options); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment