I have created a class in MVC5, where I want a primary owner of the content and then I want to have some editors for the content:
public class Content
{
The following method, OnModelCreating
, will create a working context. Not sure if it is the mapping you want though.
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
base.OnModelCreating(modelBuilder);
modelBuilder.Entity<Content>()
.HasMany(c => c.Editors)
.WithOptional()
.WillCascadeOnDelete(false);
modelBuilder.Entity<Content>()
.HasRequired(c => c.Owner)
.WithOptional()
.WillCascadeOnDelete(false);
modelBuilder.Entity<IdentityUserLogin>().HasKey<string>(l => l.UserId);
modelBuilder.Entity<IdentityRole>().HasKey<string>(r => r.Id);
modelBuilder.Entity<IdentityUserRole>().HasKey(r => new { r.RoleId, r.UserId });
}
I had the same problem and I found that I had not called
base.OnModelCreating(modelBuilder);
in my DbModel