使用EF6模拟网球轮虫

时间:2018-03-19 22:01:42

标签: database entity-framework-6 entity-relationship-model

我想创建一个网球锦标赛,我想到了这个解决方案:

public class Torneo
{
    public int Id { get; set; }
    public int NrGiocatori { get; set; }
    public virtual Provincia Provincia { get; set; }
    public virtual List<Girone> Gironi { get; set; }
    public virtual List<TurnoTabellone> TurniTabellone { get; set; }
}

public class Girone
{
    public int Id { get; set; }
    public int TorneoId { get; set; }
    public string NomeGirone { get; set; }
    public virtual List<PartitaGirone> PartiteGirone { get; set; }
}

public class PartitaGirone : Partita
{
    public int Id { get; set; }
    public int GironeId { get; set; }

}

public class TurnoTabellone
{
    public int Id { get; set; }
    public int TorneoId { get; set; }
    public Turno Turno { get; set; }
    public virtual List<PartitaTabellone> PartiteTabellone { get; set; }
}

public class PartitaTabellone : Partita
{
    public int Id { get; set; }
    public int TurnoTabelloneId { get; set; }
}

public class Partita
{
    public int IdGiocatore1 { get; set; }
    public int IdGIocaotre2 { get; set; }
    public int GameGiocatore1 { get; set; }
    public int GameGiocatore2 { get; set; }
    public DateTime DataIncontro { get; set; }
    public int OraIncontro { get; set; }
}

Torneo =锦标赛

Girone = Round Robin

PartitaGirone = Round Robin Match

TurnoTabellone = BoardRound,例如所有四分之一决赛/半决赛/决赛......

PartitaTabellone =董事会比赛

Partita =匹配

Provincia =省

这是ER模型:

enter image description here

让我感到震惊的是PARTITAGIRONE和PARTITATABELLONE中匹配字段的重复。 另一方面,由于GIRONE和TURNOTABELLONE之间的关系不同,我不能仅使用一个表来“匹配”。

任何提示? 我还避免在实体中添加玩家,因为我仍然不知道将它们放在哪里。

更新1:

如果我使用单个表进行匹配,即使我在我填充的实体的基础上有一些空的外键,该怎么办?

我用LinqPad填写一些数据进行测试:

enter image description here

enter image description here

对于Girone(Round Robin),我将TurnoTabelloneId(Round Board Id)为null,反之,如果我填写TurnoTabelloneId并且如果我不填写任何东西,我将会有第三个案例,其中包含一个不与锦标赛绑定的单一比赛。< / p>

在第一步中我不想让外键空白,但是,我想到了它,现在我觉得这不是一个坏主意。

ER的新表现是:

enter image description here

0 个答案:

没有答案