Last active
September 20, 2019 11:07
-
-
Save xltuo/544e0d310720fc1823e46bfd3bfd1ad5 to your computer and use it in GitHub Desktop.
change the table names when using ASP.NET Identity https://stackoverflow.com/questions/19460386/how-can-i-change-the-table-names-when-using-asp-net-identity
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ApplicationUser : IdentityUser | |
{ | |
public string Name { get; set; } | |
public int? Age { get; set; } | |
public string Sex { get; set; } | |
public string Desc { get; set; } | |
public async Task<ClaimsIdentity> GenerateUserIdentityAsync(UserManager<ApplicationUser> manager) | |
{ | |
// 请注意,authenticationType 必须与 CookieAuthenticationOptions.AuthenticationType 中定义的相应项匹配 | |
var userIdentity = await manager.CreateIdentityAsync(this, DefaultAuthenticationTypes.ApplicationCookie); | |
// 在此处添加自定义用户声明 | |
return userIdentity; | |
} | |
} | |
public class ApplicationRole : IdentityRole | |
{ | |
public string RoleName { get; set; } | |
public string RoleCode { get; set; } | |
public DateTime? CreateTime { get; set; } | |
public string Remark { get; set; } | |
} | |
public class ApplicationDbContext : IdentityDbContext<ApplicationUser, ApplicationRole, string, IdentityUserLogin, IdentityUserRole, IdentityUserClaim> | |
{ | |
public ApplicationDbContext() : base("DB") | |
{ | |
} | |
public ApplicationDbContext(string nameOrConnectionString) : base(nameOrConnectionString) | |
{ | |
} | |
public static ApplicationDbContext Create() | |
{ | |
return new ApplicationDbContext(); | |
} | |
protected override void OnModelCreating(DbModelBuilder modelBuilder) | |
{ | |
base.OnModelCreating(modelBuilder); | |
modelBuilder.Entity<ApplicationUser>().ToTable("Users"); | |
modelBuilder.Entity<ApplicationRole>().ToTable("Roles"); | |
modelBuilder.Entity<IdentityUserRole>().ToTable("UserRoles"); | |
modelBuilder.Entity<IdentityUserClaim>().ToTable("UserClaims"); | |
modelBuilder.Entity<IdentityUserLogin>().ToTable("UserLogins"); | |
} | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment