开发者

EF4 - Add object to objectcontext without savechanges

I have a page like Order - Order lines. Order represents by some textboxes and ddl开发者_C百科s, Order lines represents by GridView.

I want to let users add order lines without save changes to database. For example: he adds 4 order lines, fill order info and then hits Save button. Only an that moment all information should be saved to DB.

When I use code like

using (Entities ctx = new Entities())
{
 //create new OrderLine
 OrderLine ol = OrderLine.CreateOrderLine(1, 1, "", 1);
 //add OrderLine to OrderLines collection
 ctx.CreateOrderLines.AddObject(ol);
}

newly created OrderLine does not appears in my object context, so I can't access it and bind GridView to new OrderList collection.

How can I solve this problem? Or maybe there are another ways to perform this task?

Thanks.


You could try to detach the Order object and work with it until you are ready to save it back to the database.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜