Skip to content

Instantly share code, notes, and snippets.

@manoj-choudhari-git
Created June 18, 2021 10:13
Show Gist options
  • Save manoj-choudhari-git/27d3b95f93caad86ebe3c57de404266c to your computer and use it in GitHub Desktop.
Save manoj-choudhari-git/27d3b95f93caad86ebe3c57de404266c to your computer and use it in GitHub Desktop.
.NET Core - Entity Framework Core - IDesignTimeDbContextFactory Implementation
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