Having several forms that can pop-up one from another indeed poses a development challenge.
You have to define which one acts as a transaction container and commit data only once when all other forms are closed.
Because newly created objects do not have a valid identity key you will have to pass them between dialogs/forms using constructor parameters
. Use constructor parameters
to pass required
"parent" object. When the associated object has weaker relation or is optional you can use properties
to pass it. You can also define special methods that facilitate opening new dialogs using code like this (this is pseudocode!):
//this code can reside in MyParentClassEditDialog form class
MyChildClass ShowMyChildClassEditDialog(MyParentClass parentInstance)
var dialog =
//creates a new instance of the form
(dialog.ShowDialog() == DialogResult.OK)
//checks if the dialog has been closed using OK button
// TODO: do any validation from parent side if necessary
// sets the child object to the parent
parentInstance.Child = dialog.ChildInstance;
In this code snippet MyParentClass
is a class that contains one or more related child objects. MyParentClassEditDialog
class is the form used to edit/create new instance of MyParentClass
is a related class. MyChildClassEditDialog
is form that edits/creates new instances of MyChildClass
After you have build the whole object graph
in memory (passing objects arround using constructor arguments
) in the Save
button handler of MyParentClass
all you have to do is call SaveChanges()
If you are adding multiple children to a parent instead of single one, make sure to set IsManaged
flag (more info
on the bottom of the page) for the target navigation properties in your conceptual data model. This will enable OpenAccess
to track adding and deleting in collections and will make things easier for you.
Since all new your in-memory object will not have any valid identity keys
you should use the navigation properties
instead of the corresponding foreign key properties
You do not need any explicit transactions because SaveChanges()
method will wrap all SQL statements in a single transaction to ensure data integrity.
is not good idea if you plan to add Cancel
button to your dialogs. The method call will push the data to the server and as you have seen can cause unpleasant side effects.
If you have any additional questions do not hesitate to contact us.
the Telerik team
Follow @OpenAccessORM Twitter channel to be the first one to get the latest updates on new releases, tips and tricks and sneak peeks at our product labs!