MVC 5: Should I inherit my User from IdentityUser class?

后端 未结 2 1889
囚心锁ツ
囚心锁ツ 2021-01-31 00:29

I was trying to learn Asp.Net Identity and in this tutorial,

Create an Entity Framework Code First ToDo model in Models\\AppModels,cs part MyUser c

2条回答
  •  感动是毒
    2021-01-31 00:46

    The IdentityDbContext<> class is a class that inherits from DbContext as you would usually do but provides ready DbSets for Roles and Users.

    See class doc here: http://msdn.microsoft.com/en-us/library/microsoft.aspnet.identity.entityframework.identitydbcontext%28v=vs.111%29.aspx

    Yes, your user dto should inherit from IdentityUser and any additional fields you want in your database associated with your user can be added to that class.

    This makes it much easier to add additional fields to your database that are associated with your user and if you are using Entity Framework migrations and database initializes it means that you can now generate the entire Identity database from your DbContext.

提交回复
热议问题