哪些添加对象存储在ObjectContext中? [英] Where added objects are stored in ObjectContext?
问题描述
MyContext.Orders.Select(...);
我可以创建新的订单:
Order.CreateOrder(...);
并将它们添加到上下文中:
MyContext.AddToOrders(newOrder);
但是当我将新的订单添加到上下文中时,它不会显示在任何地方。我找不到它在MyContext.Orders或任何其他地方。虽然如果我调用SaveChanges,我将被成功地存储在数据库中。
这里必须非常简单,我错过了这个。
MyContext.Orders将从数据库中获取订单。
由于您的新订单
对象尚未添加到数据库,它不会显示在那里。
Suppose I have an ObjectContext of some sort with Order entities in it. So I can fetch orders from DB with:
MyContext.Orders.Select(...);
I can create new orders with:
Order.CreateOrder(...);
And add them to context:
MyContext.AddToOrders(newOrder);
But when I add new order into context it doesn't show up anywhere. I can't find it in MyContext.Orders, or anywhere else. Though If I invoke SaveChanges I'll be stored in DB successfully.
This must be something very simple I'm missing out here.
MyContext.Orders will fetch the orders from the database.
Since your new Order
object hasn't been added to the database, it won't show up there.
这篇关于哪些添加对象存储在ObjectContext中?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!