下面是模型类。数据库和表已正确创建。我可以通过邮递员向他们发布一些经过测试的数据,但是当从表中检索所有数据时,遇到了多重约束违反错误,如下图所示。在我其他应用程序中的一对多关系中,一切都按预期进行。
public class Quote
{
public Quote()
{
Outlet = new Outlet();
}
public int Id { get; set; }
public string RefNumber { get; set; }
public string Status { get; set; }
public string Name { get; set; }
public string DeliveryAddress { get; set; }
public DateTime DeliveryDate { get; set; }
public string Phone { get; set; }
public string Email { get; set; }
public string Comment { get; set; }
public DateTime Date { get; set; }
public virtual Outlet Outlet { get; set; }
}
public class Outlet
{
public Outlet()
{
Inlets = new List<Inlet>();
}
[ForeignKey("Quote")]
public int Id { get; set; }
public int OutletAngle { get; set; }
public int OutletSize { get; set; }
public string OutletType { get; set; }
public virtual Quote Quote { get; set; }
public ICollection<Inlet> Inlets { get; set; }
}
public class Inlet
{
public int Id { get; set; }
public int InletAngle { get; set; }
public int InletSize { get; set; }
public string InletType { get; set; }
}
}