Stephen,
The MSDN Documentation says
DataAdapter.Update(DataSet) -- Will call commands on all rows in the
dataset.
That is Incorrect. (Yes the MSDN docs are incorrect on this, sorry - but hey
look at it this way, 99.999% of the times the docs ar right .. hehe
)
So what do you do?
First the truly accurate behavior of DataAdapter.Update(dataset) <--- This
will call the I,U,D commands on the rows of the table identified by "Table"
<-- usually the first table in the dataset unless you have specified
TableMappings, and it will ignore others.
Your approach of specifying cascade on the FK is correct, so you are on the
right path. However, persisting relational data is a pain in the booty. This
is a frequently asked question, so I wrote a long blog post about it
sometime back - the rest of your answer is right here -
http://codebetter.com/blogs/sahil.malik/archive/2005/05/06/62893.aspx
BTW - I know you will cry out loud about the fact that DataAdapter.Update
should have taken care of it all for you? The truth however is, that it just
cannot. Given that there are an infinte number of relation possibilities,
and the exact I,U,D logic depends on the relation structure, it is
impossible to write an object and have it perform well that will take care
of all circumstances.
BTW, This is covered in my upcoming book - Chapter #10 & 11.
- Sahil Malik [MVP]
Upcoming ADO.NET 2.0 book -
http://tinyurl.com/9bync