实体框架是否支持通过如下导航属性自下而上进行保存?我在 ORDERID 上收到一个 FK 约束错误,提示不是。ORDERID 是 ORDERID 的 FK(但这不是 PK)
someOrderItemEntity.OrderEntity = someOrderEntity;
someOrderItemEntity.ORDERID = someOrderEntity.ORDERID;
context.OrderItems.Add(someOrderItemEntity);
context.SaveChanges();
public partial class OrderEntity
{
public int ID { get; set; }
public int ORDERID { get; set; }
public virtual ICollection<OrderItemEntity> OrderItemEntities{ get; set; }
}
public partial class OrderItemEntity
{
public int ID { get; set; }
public int ORDERID { get; set; }
public virtual OrderEntity OrderEntity{ get; set; }
}