0
我对EF
的数据库设计非常陌生,并试图了解如何将我的实体模型正确转换为数据库表。多个表的一对多关系
我有以下两类:
public class Test
{
public int ID { get; set; }
// ... more data
ICollection<Exception> Exceptions { get;set; }
}
public class Measurement
{
public int ID { get; set; }
// ... more data
ICollection<Exception> Exceptions { get;set; }
}
所以我的两个类测试与测量将包含Exception
对象列表
我的计划是落实以下列方式异常:
public class Exception
{
public int ID { get; set; }
// ... more data
/// <summary>
/// Reference to Test to create One-To-Many relationship
/// </summary>
public Test Test{ get; set; }
/// <summary>
/// Foreign key of Test table
/// </summary>
public int TestID { get; set; }
/// <summary>
/// Reference to Measurement to create One-To-Many relationship
/// </summary>
public Measurement Measurement { get; set; }
/// <summary>
/// Foreign key of Measurement table
/// </summary>
public int MeasurementID { get; set; }
}
这样,我的每个Exception实体都将具有测试和测量表的外键,但是在每个Exception实体中测试或测量将被呈现,因为一个例外不能来自测试或测量。
这有效,但我想知道如果这是正确的路要走,或者如果有更好的做法。
感谢
你问的代码审查确定测试
对不起? – Biscuits
不是代码审查,而是更多的策略。 – inside
可能希望使测试和测量属性为虚拟。 –