我有以下 EF 模型:
public class Order
{
public string Id { get; set; }
public IList<OrderLine> Lines { get; set; }
...
}
public class OrderLine
{
public string OrderId { get; set; }
public int Position { get; set; }
...
}
的主键OrderLine
由OrderId
和组成Position
:
HasKey(l => new {l.Position, l.OrderId});
到目前为止一切都很好,直到我添加了这个新实体:
public class OrderLineReturn
{
public string Id { get; set; }
...
}
public class OrderLine
{
public string OrderId { get; set; }
public int Position { get; set; }
public IList<OrderLineReturn> LineReturns { get; set; }
...
}
现在删除订单时出现错误:
DELETE instruction is in conflict with the REFERENCE constraint "FK_dbo.OrderLineReturn_dbo.OrderLine_OrderLine_Position_OrderLine_OrderId"
谁能帮我理解这个问题?