Supposing
I have to call multiple Stored Procedures for a task that have to be executed inside a transaction, one of which creates a Department entry, and the other a Role for that department, then
from a best practices perspective, what is advisable?
1) I create a separate method in the DAL that call the SP to create the role.
Then, have my BL class call the methods for creating department &
then the Role one after the another. In that case, the BL would need to
be aware of the underlying transaction in some way, and would need to
request the DAL to commit, if everything is fine.
2) Have my DAL method to create the department perform 2 operations:
i) Create department, and then ii) Create Role. In this case, the BL
would be totally abstracted from the underlying trasanction, as the DAL
can itself decide when to commit or abort.
To me, although the second approach seems more attractive from an
implementation point, but logically, the method for creating department
should only do that. It is the BL that knows, that creation of
department should be followed by creation of a role for that department!!!