On what basis should one decide to use IdentityDbContext
versus IdentityDbContext<ApplicationUser>
in an ASP.NET MVC5 application?
What benefits do we get by using IdentityDbContext<ApplicationUser>
instead of the non-generic IdentityDbContext
?
IdentityDbContext() Initializes a new instance of the IdentityDbContext class. IdentityDbContext(DbContextOptions) Initializes a new instance of IdentityDbContext.
In order to create a database object, we need to create a separate DbContext class. This can be called ApplicationDbContext and will implement DbContext. So now, if we want to add a model, we can add it inside the ApplicationDbContext constructor.
IdentityDbContext<ApplicationUser>
will let you use your own ApplicationUser
class as the User
entity. I.e. you can have custom properties on your users. The IdentityDbContext
class inherits from IdentityDbContext<IdentityUser>
which means you will have to use the IdentityUser
class for your users.
If you want to have more properties on your user objects than the few properties that IdentityUser
provide (UserName, PasswordHash and a few more) then you may want to choose IdentityDbContext<ApplicationUser>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With