【问题标题】:Code First Modelling Relationships代码优先建模关系
【发布时间】:2012-07-15 12:09:58
【问题描述】:

我正在尝试在代码优先 EF 中对此进行建模。比赛可以特定于一个国家(例如本地联赛,这也意味着一个大洲)、仅一个大洲(例如欧洲杯)或两者都不是(例如世界杯)

我有一个针对竞赛、国家和大陆的课程。国家和大陆之间存在一对多的关系。我如何为比赛建模?这似乎不正确

public class Competition{
 public int CompetitionID { get; set; }
 public int Name { get; set; }
 public virtual ICollection<Season> Seasons { get; set; }
 public Country? Country { get; set; }
 public Continent? Continent { get; set;}
}

【问题讨论】:

    标签: entity-framework ef-code-first code-first


    【解决方案1】:

    比赛和国家/大陆之间存在多对多的关系,因此您的比赛类应该有一个名为 zoneID 的属性(可以是国家或大陆)

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2012-12-06
      • 2018-05-31
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2023-03-23
      • 1970-01-01
      相关资源
      最近更新 更多