码迷,mamicode.com
首页 > Web开发 > 详细

ASP.NET MVC 5 Identity 默认表映射修改

时间:2015-10-23 18:26:37      阅读:293      评论:0      收藏:0      [点我收藏+]

标签:

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

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!