When using IdentityDbContext alongside another DbContext, an InvalidOperationException is thrown. This is due to the usage of the generic DbContextOptions in the IdentityDbContext constructor (not an issue in the VS templates due to the ApplicationDbContext constructor).
The DbContextOptions passed to the Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityDbContext constructor must be a DbContextOptions<Microsoft.AspNetCore.Identity.EntityFrameworkCore.IdentityDbContext>. When registering multiple DbContext types make sure that the constructor for each context type has a DbContextOptions<TContext> parameter rather than a non-generic DbContextOptions parameter.
Could you try to use a Generic parameter like that?
public IdentityDbContext (DbContextOptions<IdentityDbContext > options)
: base(options)
{
}
Currently I'm using the following workaround, similar to what you suggested:
public class ApplicationDbContext : IdentityDbContext {
public ApplicationDbContext(DbContextOptions<ApplicationDbContext> options) : base(options) { }
}
Seems a bit odd to be made to do this when you want to use more than one DbContext in a project. Shouldn't this be the default behavior of the library?
Most helpful comment
Currently I'm using the following workaround, similar to what you suggested:
Seems a bit odd to be made to do this when you want to use more than one
DbContextin a project. Shouldn't this be the default behavior of the library?