我正在使用像这样的自定义用户模型:
public class ApplicationUser : IdentityUser
{
public string Firstname { get; set; }
...
}
身份系统创建的其余表有点不同步。创建了一个名为 ApplicationUser_Id 的新列,该列设置在外键处,但仍有一个 UserId 用作复合主键。
ApplicationUser 模型的配置是
public class ApplicationUserConfiguration : EntityTypeConfiguration<ApplicationUser>
{
public ApplicationUserConfiguration()
{
this.ToTable("AspNetUsers");
this.Property(u => u.Firstname).IsRequired().HasMaxLength(100);
this.Property(u => u.Lastname).IsRequired().HasMaxLength(100);
}
}
我如何告诉 EF 继续使用 UserId 作为外键并删除 ApplicationUser_Id?
谢谢
更新: 在我为 ApplicationUser 添加自定义配置之前按预期工作。
DataContext.cs
modelBuilder.Configurations.Add(new ApplicationUserConfiguration());
应用用户配置.cs
public class ApplicationUserConfiguration : EntityTypeConfiguration<ApplicationUser>
{
public ApplicationUserConfiguration()
{
this.ToTable("AspNetUsers");
this.Property(u => u.Firstname).IsRequired().HasMaxLength(100);
this.Property(u => u.Lastname).IsRequired().HasMaxLength(100);
}
}
最佳答案
我确实重现了这个问题,然后我通过添加 modelBuilder.Configurations.Add(new ApplicationUserConfiguration()); 修复了它 前 base.OnModelCreating(模型构建器); 所以现在的功能
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Configurations.Add(new ApplicationUserConfiguration());
base.OnModelCreating(modelBuilder);
}
关于c# - ASP.net Identity 自定义用户模型未被角色、声明和登录表使用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34658411/