Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is the difference between IdentityDbContext and IdentityDbContext<ApplicationUser> in MVC5

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?

like image 644
Sandeep Kumar Avatar asked Nov 29 '13 08:11

Sandeep Kumar


People also ask

What is IdentityDbContext?

IdentityDbContext() Initializes a new instance of the IdentityDbContext class. IdentityDbContext(DbContextOptions) Initializes a new instance of IdentityDbContext.

Why we use ApplicationDbContext?

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.


1 Answers

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>

like image 162
Olav Nybø Avatar answered Sep 28 '22 12:09

Olav Nybø