ฉันมีปัญหากับความสัมพันธ์แบบกลุ่มต่อกลุ่ม
ฉันมี 3 คลาสโมเดล:
- บทความ - >>> รายการ
- คำหลัก - >>> คำหลัก
- TableForRelation ระหว่างบทความและคำหลัก - >>> ItemKeywords
ด้วย Entity Framework Core ฉันเขียน 3 คลาสนี้และทำงานได้ดี
public class Item
{
public int Id { get; set; }
public string Content { get; set; }
public virtual ICollection<ItemKeyWords> ItemKeyWords { get; set; }
}
public class KeyWord
{
public int Id { get; set }
public string Text { get; set; }
public virtual ICollection<ItemKeyWords> ItemKeyWords { get; set; }
}
public class ItemKeyWords
{
public int Id { get; set; }
public int ItemId { get; set; }
public virtual Item Item { get; set; }
public int KeyWordId { get; set; }
public virtual KeyWord KeyWord { get; set; }
}
คำถามคือ: ฉันจะบอก Entity Framework ได้อย่างไรหากมี Keyword
อยู่ อย่าใส่สิ่งนั้นลงในตารางคำหลักและเพียงสร้างความสัมพันธ์กับสิ่งนั้นในตาราง ItemKeywords