I've got a self-referential Role table that signifies a tree structure
ID [INT] AUTO INCREMENT Name [VARCHAR] ParentID [INT]
I'm utilizing an ADO.Internet DataTable and DataAdapter to load and save values for this table. This works basically only create kids of existing rows. Basically create a child row, make a young child of this child, then Update, the temporary ID value produced through the DataTable is certainly going in to the ParentID column. I've the next data relation set:
dataset.Relations.Add(New DataRelation("RoleToRole",RoleTable.Columns("ID"), RoleTable.Columns("ParentID")))
So when I make new child rows within the DataTable I call the SetParentRow method
Can there be something I must do to obtain the ID generation to propagate recursively after i call Update around the DataAdapter?
I'm not sure ADO.internet particularly, but many ORMs will not instantly place the ID of the new record inside a relationship. You will need to lean towards the 2-step process:
- build and save parent
- build and save child with relationship to parent
Why this really is hard for ORMs happens because you may have circular dependencies, also it wouldn't know which object it required to create an ID for first. Some ORMs are wise enough to determine individuals associations where you will find no such circular dependencies, but many aren't.
Will it make a difference should you go
It is best to give a ForeignKeyConstraint, with UpdateRule set to Cascade.