Map tables using fluent api in asp.net MVC5 EF6?

前端 未结 3 1550
礼貌的吻别
礼貌的吻别 2020-12-17 17:03

I am trying to add profile/Membership information into my MVC5 application and adding configuration mappings.

I get the following error message:

3条回答
  •  Happy的楠姐
    2020-12-17 17:21

    Follow these steps around OnModelCreating method and test after each one to be aware of taking effect:

    1. Make sure you have one Context to prevent of their rule conflicts.
    2. Call base.OnModelCreating(modelBuilder); inside the mentioned method (first of all)
    3. Add the followings plus previews step in the method:


    modelBuilder.Entity().HasKey(l => l.UserId);
    modelBuilder.Entity().HasKey(r => r.Id);
    modelBuilder.Entity().HasKey(r => new { r.RoleId, r.UserId });
    

提交回复
热议问题