实体框架核心外键问题

时间:2019-06-19 09:58:21

标签: sql-server entity-framework .net-core entity-framework-core

尝试运行update-database -verbose时遇到以下问题:

  

介绍FOREIGN KEY约束   表格上的“ FK_Customizations_Specifications_SpecificationId”   “自定义”可能会导致循环或多个级联路径。指定   ON DELETE NO ACTION或ON UPDATE NO ACTION,或修改其他FOREIGN   关键约束。无法创建约束或索引。见前   错误。

这些类如下:

public class Specification : BaseEntity
{
    public double Km { get; set; }
    public double Price { get; set; }
    public SpecificationType Type { get; set; }
    public string Notes { get; set; }
    public bool IsLeasing { get; set; }
    public DateTime? EndLeasingDate { get; set; }
    public string LeasingCompany { get; set; }
    public DateTime? ExpectedDeliveryToReseller { get; set; }
    public DateTime? ActualDeliveryToReseller { get; set; }
    public DateTime? ExpectedDeliveryToCustomer { get; set; }
    public DateTime? ActualDeliveryToCustomer { get; set; }

    public ICollection<Customization> Customizations { get; set; }
    public int VehicleId { get; set; }
    public Vehicle Vehicle { get; set; }
    public int ContractId { get; set; }
    public Contract Contract { get; set; }
}
public class Customization : BaseEntity
{
    public string Description { get; set; }
    public DateTime? ExpectedStartDate { get; set; }
    public DateTime? ExpectedEndDate { get; set; }
    public DateTime? ActualStartDate { get; set; }
    public DateTime? ActualEndDate { get; set; }
    public decimal Price { get; set; }

    public int SpecificationId { get; set; }
    public Specification Specification { get; set; }
    public int ContactId { get; set; }
    public Contact Contact { get; set; }
}

现在我可以理解,在Customization中包含SpecificationId可能会带来一些问题,但是阅读here on Convenction4时他们说我可以做到这一点。我缺少什么?也许他们忘记了我必须在OnModelCreating中添加一些内容?

0 个答案:

没有答案