【发布时间】:2014-11-05 06:34:23
【问题描述】:
我有两张表,Order 和 OrderItems
Order 表有一个 OrderId 列,它是主键 OrderItems 也有此列作为外键。
对于给定的订单,如果 OrderId 为 1 并且它有两个项目,则 OrderItems 表 将有两行,每行的 OrderID 为 1。
我使用 EF 为这两个表创建了一个上下文。
现在 Order 表和 OrderItems 表都有一个 Status 列。
使用 GraphDiff 我想像这样更新这个值:
using (var ordersContext = new OrdersContext())
{
ordersContext.UpdateGraph(orderToUpdate, map => map.OwnedCollection(p => p.OrderItems));
ordersContext.SaveChanges();
}
这给出了以下异常:
GraphDiff supports detached entities only at this time. Please try AsNoTracking() or detach your entites before calling the UpdateGraph method
有什么线索吗?
提前致谢。
【问题讨论】:
标签: c# entity-framework graphdiff