ASP标识表列更改,但新列名称无法进行映射

我已经更改了asp Identity,因此在AspNetIdentity表的数据库Id列中是UserId

 modelBuilder.Entity() .Property(p => p.Id) .HasColumnName("UserId"); 

这很好。 生成的表具有UserId而不是Id
现在我有另一个表,应该用UserIdAspNetUsers映射:
这样写时:

 public class JobApply { ... public int UserId { get; set; } public virtual ApplicationUser ApplicationUser { get; set; } 

数据库中的表格如下:
在此处输入图像描述
如果我这样写:

 public class JobApply { ... public int ApplicationUserId { get; set; } public virtual ApplicationUser ApplicationUser { get; set; } 

数据库看起来像:
在此处输入图像描述

第一个选项创建了UserId字段,但它不是FK而是将新字段添加为FK
我如何正确映射这个以使表JobApply与字段UserId成为FKAspNetUsers

UPDATE

当我添加这个:

 base.OnModelCreating(modelBuilder); modelBuilder.Entity() .Property(p => p.Id) .HasColumnName("UserId"); modelBuilder.Entity() .HasRequired(e => e.ApplicationUser) .WithMany() .HasForeignKey(e => e.UserId); 

表关系如下所示:
在此处输入图像描述
这是两个类:

 public class ApplicationUser : IdentityUser { public string Email { get; set; } public string ConfirmationToken { get; set; } public bool IsConfirmed { get; set; } public string PasswordResetToken { get; set; } public int CityId { get; set; } public virtual City City { get; set; } public virtual ICollection JobApplies { get; set; } } public class JobApply { public int JobApplyId { get; set; } public int UserId { get; set; } public int JobId { get; set; } public int JobApplyStatusId { get; set; } public DateTime CreatedDate { get; set; } public virtual ApplicationUser ApplicationUser { get; set; } public virtual Job Job { get; set; } public virtual JobApplyStatus JobApplyStatus { get; set; } } 

使用流畅的API定义您的关系,如下所示:

 modelBuilder.Entity() .HasRequired(e => e.ApplicationUser) .WithMany(e => e.JobApplies) .HasForeignKey(e => e.UserId); 

您也可以从ApplicationUser类中删除属性UserId ,然后像这样定义映射:

 modelBuilder.Entity() .HasRequired(e => e.ApplicationUser) .WithMany(e => e.JobApplies) .Map(m => m.MapKey("UserId"));