New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

IdentityDbContext and generic DbContextOptions parameter #962

scottbrady91 opened this Issue Sep 13, 2016 · 2 comments


None yet
4 participants

scottbrady91 commented Sep 13, 2016

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.


This comment has been minimized.

itsfelipesan commented Sep 21, 2016

Could you try to use a Generic parameter like that?

public IdentityDbContext (DbContextOptions<IdentityDbContext > options)
   : base(options)

This comment has been minimized.

scottbrady91 commented Sep 22, 2016

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?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment