I have created 2 DbContexts for a new ASP.Net Core app.
They are both derived from the same ApplicationDbContext base class, with the only difference being the OnConfiguring override, where UseMySql is used instead of UseSqlite, following what is suggested in this post about multiple providers.
SqliteDbContext.cs has this:
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
#if DEBUG_EF
options.UseSqlite("DataSource=");
#endif
}
MySqlDbContext.cs has this:
protected override void OnConfiguring(DbContextOptionsBuilder options)
{
#if DEBUG_EF
options.UseMySql("Server=");
#endif
}
The following command was run:
dotnet ef migrations add InitialCreate --context MySqlDbContext --output-dir Migrations/MySql --configuration DebugEf
Error returned is:
Unable to create an object of type 'MySqlDbContext'. For the different patterns supported at design time, see https://go.microsoft.com/fwlink/?linkid=851728
However, the following command, which uses the context for Sqlite, is successful.
dotnet ef migrations add InitialCreate --context SqliteDbContext --output-dir Migrations/Sqlite --configuration DebugEf