<p>I have a self-referential Role table that represents a tree structure </p>

<pre><code>ID [INT] AUTO INCREMENT
Name [VARCHAR]
ParentID [INT]
</code></pre>

<p>I am using an ADO.NET DataTable and DataAdapter to load and save values to this table. This works if I only create children of existing rows. If I make a child row, then make a child of that child, then Update, the temporary ID value generated by the DataTable is going into the ParentID column. I have the following data relation set:</p>

<pre><code>dataset.Relations.Add(New DataRelation("RoleToRole",RoleTable.Columns("ID"), RoleTable.Columns("ParentID")))
</code></pre>

<p>And when I make new child rows in the DataTable I call the SetParentRow method</p>

<pre><code>newRow.SetParentRow(parentRow)
</code></pre>

<p>Is there something special I have to do to get the ID generation to propagate recursively when I call Update on the DataAdapter?</p>

[{'answer_id': 5497, 'author': 'lomaxx', 'author_id': 493, 'author_profile': 'https://Stackoverflow.com/users/493', 'pm_score': 0, 'selected': False, 'text': '<p>Does it make any difference if you go</p>\n\n<pre><code>newRow.SetParentRow(parentRow, RoleTable.Relations("RoleToRole"))\n</code></pre>\n'}, {'answer_id': 24472, 'author': 'James A. Rosen', 'author_id': 1190, 'author_profile': 'https://Stackoverflow.com/users/1190', 'pm_score': 3, 'selected': True, 'text': "<p>I don't know ADO.net in particular, but most ORMs won't automatically insert the ID of a new record in a relationship.  You'll have to resort to the 2-step process:</p>\n\n<ol>\n<li>build and save parent</li>\n<li>build and save child with relationship to parent</li>\n</ol>\n\n<p>The reason that this is difficult for ORMs is because you might have circular dependencies, and it wouldn't know which object it needed to create an ID for first.  Some ORMs are smart enough to figure out those relationships where there are no such circular dependencies, but most aren't.</p>\n"}, {'answer_id': 157189, 'author': 'Joe', 'author_id': 13087, 'author_profile': 'https://Stackoverflow.com/users/13087', 'pm_score': 0, 'selected': False, 'text': '<p>I suggest you add a ForeignKeyConstraint, with UpdateRule set to Cascade.</p>\n'}]
['https://Stackoverflow.com/questions/5263', 'https://Stackoverflow.com', 'https://Stackoverflow.com/users/173/']