Resolving 'No key Defined' errors while using OnModelCreating with ApplicationDbContext?

后端 未结 3 867
我寻月下人不归
我寻月下人不归 2021-01-12 11:40

I\'ve been trying to create navigation properties for my collection types and I found this example of how one person accomplished it using OnModelCreating. I gave it a try i

3条回答
  •  抹茶落季
    2021-01-12 11:59

    You might have to add something like the following to OnModelCreating

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

    See also:

    • Map tables using fluent api in asp.net MVC5 EF6?
    • User in Entity type MVC5 EF6

提交回复
热议问题