我有一个代码优先的MVC4 C#应用程序,这两个模型
public class ClassRoom {
public int ID { get; set; }
public string ClassName { get; set; }
public virtual ICollection<Pupil> Pupils { get; set; }
}
public class Pupil {
public int ID { get; set; }
public string PupilName { get; set; }
public virtual ICollection<ClassRoom> ClassRooms { get; set; }
}
这是上下文的一部分
modelBuilder.Entity<Location>()
.HasMany(l => l.ClassRooms)
.WithMany(o => o.Pupils)
.Map(m => m.MapLeftKey("PupilID")
.MapRightKey("ClassRoomID")
.ToTable("PupilClassRoomMM"));
因此,有一个名为“PupilClassRoomMM”的多对多表。
这一切都运行正常,但现在我想在PupilClassRoomMM表中添加一列。 我试图制作这个模型,但Add-Migration没有得到它。
public class PupilClassRoomMM
{
[Key, Column(Order = 0)]
public int ClassRoomID { get; set; }
[Key, Column(Order = 1)]
public int PupilID { get; set; }
public bool IsPrimary { get; set; }
}
错误是:
"PupilClassRoomMM: Name: The EntitySet 'PupilClassRoomMM' with schema 'dbo' and
table 'PupilClassRoomMM' was already defined.
Each EntitySet must refer to a unique schema and table."
如何将字段添加到已存在的多对多表中(我不想丢失其数据)。