I have a web site similar to wizard from 4 steps . The site is implemented by asp.net web forms.
The wizard try to build and object and add it to the DB.
The object graph is following :
class A { B bObject ; C cObject ; D dObject}
class B {} ; class C{}; class D{};
the objects b,c,d are fetched from the database during the wizard step and filled into A.
As you know , b,c,d fetched from the DB by different contexts.
When I come to the final step to save A to the DB , the context recognize b,c,d as new objects and not just unmodified so only link them because they come from different contexts.
Any suggestion to make a clean way solving this issue ?
The different contexts caused because of the post packs.
This is one of those cases where the best answer is “don’t do that!”
One way to handle this is to just have the wizard steps gather all the data necessary to create the database tables from the user, and save the data in Session state. Only when the final wizard step is executed would you then take the data from Session state and use it to create EF entities and then save the changes, all on a single context.
Another way would be to save the object graph as EF objects (still in Session state), but then, in the final wizard step, open a context and use the
Attachmethod to attach the objects to the current context. Again, this uses a single context.