views:

104

answers:

1

Hi

I use ADO.NET Entity-Framework, I have a page that is data-bound to an entity variable in the code file.

The hierarchy of the item is Person.Orders I want the user to add/remove orders to this Person entity (Person.Orders.Add(order)), The problem is that while the entity is not saved yet, once the user makes a post back, the variables are disposed and the person and all its orders are gone. What should be a good practice on saving entities/variables (complex ones) in cache/memory/state or whatever (not save in the store, i want to save items in the store only when the user clicks the general Accept Changes btn, meanwhile i wanna build the hierarchy on the air)?

If I am not clear enough I will provide more details tomorrow, please accept my apology.

+1  A: 

Use session state to keep your object hierarchy while you expect several action on the client and load your entities on each view reload. This way you'll reflect user changes and you'll keep them in memory 'till the final action is triggered at which point you'll probably save the entire entity hierarchy.

But be aware of the appdomain being unloaded in the middle of your user's job if you're using inproc session.

That sounds fair enough to me. how is this done in short words?Thanks in advance!
Shimmy
In short words...okay. A combination of your page URL (including query string) should tell you what the action is and should give you some kind of a key for you to get the entity (something like addOrder.aspx?person=xxx). So you get the person previously stored in session by that xxx key.
I was asking about how technically to store the object in the session, won't it cause a performance problem, or everyone does so?
Shimmy
Okay so your question is HOW to use the session or IF you should use it?