Skip to content

MigrationsExtensionsDbContextDesignTimeFactory Class

Dennis C. Mitchell edited this page Mar 28, 2019 · 6 revisions

This class is a generic implementation of Microsoft.EntityFrameworkCore.Design.IDesignTimeDbContextFactory. The class makes it easier to use Entity Framework Migrations with DbContext classes that have only a single constructor taking DbContextOptions as a parameter.

Special Note: The class targets SQL Server only, and it requires the following NuGet package: EDennis.MigrationsExtensions

Usage Steps

  1. Create a subclass of MigrationsExtensionsDbContextDesignTimeFactory, where the type parameter is the name of your DbContext class.
  2. Create a ConnectionStrings object in appsettings.Development.json and add a property whose key is the name of your DbContext class and whose value is the connection string.

Example

public class AgencyInvestigatorCheckContextDesignTimeFactory :
    MigrationsExtensionsDbContextDesignTimeFactory<AgencyInvestigatorCheckContext> { }

Clone this wiki locally