代码之家  ›  专栏  ›  技术社区  ›  Mihai Alexandru-Ionut

如何使用一个公共表创建一对一关系?

  •  0
  • Mihai Alexandru-Ionut  · 技术社区  · 7 年前

    我有三张桌子:

    Connection(OwnerGuid, ConnectionTypeId, Connection)
    Instrument(Id, Guid, Model, Name, Description)
    LaboratoryInfoSystem(Id, Guid, Model, Name, Description)
    

    以及 rule 是那个吗 Instrument 只有一个连接和一个 LaboratoryInfoSystem 也只有一个连接。所以这两者之间的关系 仪器 Connection 也是一对一 实验室系统 连接 .

    想法是 连接 表将保留连接 LaboratortInfoSystem 仪器 .为此,我声明 实验室磷系统 连接 通过使用 Guid 字段作为外键和主键 连接 表。

    有更好的方法吗?

    也在我使用后 Entity Framework 仪器 我班有这个:

    public virtual Connection Connection { get; set; }
    

    但是在 连接 我有:

    public virtual ICollection<Instrument> Instruments { get; set; }
    

    这告诉我关系不是 one-to-one .

    我怎么解决这个问题?

    1 回复  |  直到 7 年前
        1
  •  1
  •   George Menoutis    7 年前

    Each Instrument has one connection Each LaboratoryInfoSytem has one Connection Instrument:Connection 1:1 LaboratoryInfoSytem:Connection 1:1

    polymorphic association this article