I am working on both parts of a data layer. I get to create the procs, and the business object layer that will consume the procs.
Is there a best practice for determining where a delete should occur?
Here’s the scenario. I have a table Book with foreign key to a child table Pages. If I delete the book, I also want to delete the pages. If the deletion of a page fails, I want the whole book to stay (transaction).
Should the delete occur in managed code (by creating a transaction, deleting all child objects and finally the book), or in the proc (again in a transaction)?
Or does it matter?
I would say it depends where you store your ‘logic’ for the data.
1) If your stored procedures are mostly ‘dumb’ ones with simple Inserts/Update/Delete. I would put the deletes in the data layer object where you would have more complex code.
2)IF you have written many complex stored procedure, where you need to check biz rules. Keep the logic all in the SPs and keep the data layer simple.
Really it where you want the complexity to lie. Don’t put too many rules in both the objects and the SPs, or else maintenance will be a bitch.