标签:
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
if (modelBuilder == null)
{
throw new ArgumentNullException("modelBuilder");
}
?
var user = modelBuilder.Entity<IdentityUser>()
.ToTable("Users");
user.HasMany(u => u.Roles).WithRequired().HasForeignKey(ur => ur.UserId);
user.HasMany(u => u.Claims).WithRequired().HasForeignKey(uc => uc.UserId);
user.HasMany(u => u.Logins).WithRequired().HasForeignKey(ul => ul.UserId);
user.Property(u => u.UserName)
.IsRequired()
.HasMaxLength(256)
.HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("UserNameIndex") { IsUnique = true }));
?
user.Property(u => u.Email).HasMaxLength(256);
?
modelBuilder.Entity<IdentityUserRole>()
.HasKey(r => new { r.UserId, r.RoleId })
.ToTable("UserRoles");
?
modelBuilder.Entity<IdentityUserLogin>()
.HasKey(l => new { l.LoginProvider, l.ProviderKey, l.UserId })
.ToTable("UserLogins");
?
modelBuilder.Entity<IdentityUserClaim>()
.ToTable("UserClaims");
?
var role = modelBuilder.Entity<IdentityRole>()
.ToTable("Roles");
role.Property(r => r.Name)
.IsRequired()
.HasMaxLength(256)
.HasColumnAnnotation("Index", new IndexAnnotation(new IndexAttribute("RoleNameIndex") { IsUnique = true }));
role.HasMany(r => r.Users).WithRequired().HasForeignKey(ur => ur.RoleId);
}
ASP.NET MVC 5 Identity 默认表映射修改
标签:
原文地址:http://www.cnblogs.com/BlueEye/p/4904873.html