哪些添加对象存储在ObjectContext中? [英] Where added objects are stored in ObjectContext?

查看:119
本文介绍了哪些添加对象存储在ObjectContext中?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个ObjectContext,其中有一些Order实体。所以我可以从DB获取订单:

  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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆