Relationships in Typed Datasets

Hello

I am just woundering about something, which i will be doing in the near future but have not got around to yet, and just thought i would ask the question before i approachs this.


Lets say i have 2 Typed Data Tables

  1. Orders
  2. OrderDetails

Now in the SQL Database these 2 tables are related by a foreign key relationship. Which have the "Enforce Foreign Key Constraint" for Update and Delete Rule.
(Meaning that when i delte an order, SQL auto deletes all the Order Details for that order)

Now say in .Net aplcation i have my Typed Datatables with the same relationship, and also have the Casade rule set.

Now does this meen that when i delete an order from my local typed order table, and it auto deletes from the local orderdetail table, now i call update on the tables,and it deletes the Order entry as expected, but then the SQL takes over deletes the order details, then it goes back to .net transaction goes to remove the orderdetails rows from the table and fails because sql server has already deleted them

Is this what happens, or should i only set the casade rule in 1 place

Please dont forget i have not actually done and tested this yet, i was just woundering what sequence of events will happen

Thanks Lee




Answer this question

Relationships in Typed Datasets

  • Dario Aznar

    Set the rule in your dataset also...and the dataset will go through and delete the child records when deleting the parent...and then when you update the SQL db...it will send the parent delete to SQL and SQL will take care of deleting the child rows

    As a rule the strong typed dataset should mimic/mirror the actual db data...and the updates between the dataset and db will be transparent once called on the dataset



  • Paulustrious

    ok this sounds logical but lets say that when i delete the DS parent it auto deletes the child in the local DS

    Now when the local DS update method is called

    Will it not try to call a delete on a child row which does not exist as SQL server has already deleted it

    and if it does fail to do the delete roll the transaction right back

    Thanks Lee



  • Relationships in Typed Datasets