我想爲課程分配一個EXISTING CHILD對象列表。但我得到PK問題或重複行。由於天可以選中或取消選中,我應該先刪除全部,然後再添加全部。實體框架通過多對多關係將現有子對象分配給父對象
Course()
{
int Id {get;set;}
string Descripcion {get;set;}
List<DayOfWeek> Days {get;set;}
}
DayOfWeek()
{
int Id {get;set;}
string Name {get;set;}
List<Course> Courses {get;set;} //Just for Entity Framework to create the many-to-many relation
}
一些其它INFO
- 碼第一
- 遲緩裝載
- 斷開(庫/ servide的WebAPI層,UI層)
- 實體和DTO的物體,例如課程映射到CourseData上的UI,反之亦然。
當我安裝一個新的對象,它被設置爲添加,我需要修復
你不顯示你想修復的代碼。 –
看到[這裏](https://stackoverflow.com/questions/14307838/entity-framework-adding-existing-child-poco-to-new-parent-poco-creates-new-chi)和[這裏](https ://stackoverflow.com/questions/6823947/adding-item-with-many-to-many-relationship-in-entity-framework)併發布你正在嘗試的更新代碼。 –