ASP Identity table column change but mapping is not possible with new column name

前端 未结 1 1291
离开以前
离开以前 2021-01-23 07:00

I have changed the asp Identity so that in database Id column of AspNetIdentity table be UserId:

modelBuilder.Entity

        
相关标签:
1条回答
  • 2021-01-23 07:20

    Define your relationship with the fluent API like this:

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

    You may as well remove the property UserId from the ApplicationUser class and then define the mapping like this:

    modelBuilder.Entity<JobApply>()
                        .HasRequired(e => e.ApplicationUser)
                        .WithMany(e => e.JobApplies)
                        .Map(m => m.MapKey("UserId"));
    
    0 讨论(0)
提交回复
热议问题