.net core modify Identity / AspNetUsers database

  As we all know, .net core of a complete user management functions. It can be achieved using the user's login and logout management functions. Now the question is, we sometimes need to add some fields, how to do it? Of course, he is to modify it. Modify Reference Links: https://medium.com/@nativoplus/asp-net-core-identity-3-0-6018fc151b4

  In conclusion, the first step is to create the Entity, and inherit IdentityUser.

  The second step, modify Startup, modified to use Identity of the user object (ApplicationUser) in ConfigureServices, the role I have not changed, not changed:

    

   services.AddIdentity <ApplicationUser, IdentityRole> () 
                .AddEntityFrameworkStores <ApplicationDbContext> () 
                .AddDefaultTokenProviders ();

  A third step of modifying the database context object, specified in the table corresponding user ApplicationUser method OnModelCreating

  

// context inherited from IdentityDbContext

public class ApplicationDbContext : IdentityDbContext<ApplicationUser>
//修改OnModelCreating 方法
modelBuilder.Entity<ApplicationUser>(entity => { entity.ToTable("AspNetUsers", "dbo"); }

  At this point it. After modify the field can use EF migration command to update the database, you can then modify the database manually modify ApplicationUser object, which applies to the project structure of db first

Guess you like

Origin www.cnblogs.com/jidanfan/p/11516685.html