We are using 3 layered architechture which contains
SqlHelper -> DAL(Data access layer) -> BAL -> UI
Any class within a DAL can call another DAL same way any BAL can call another BAL or DAL of its own.
eg.
class Customer_DAL { display_CusDal(); }
class Customer_BAL { display_CusBal(); }
class Product_DAL { display_ProDal(); }
class Product_BAL { display_ProBal(); }
display_CusDal()
{
//call display_ProDal()
//Do some work
}
display_CusDal function should run as a transaction which intern means any insertion made within this function should be associated with transaction object.
Since display_CusDal can call display_ProDal which might or might not be inserting data in table in another transaction, so I need to handle these in transactions.
What approach should I use.
SqlTransactions only work with SQL and require you to add usage of them explicitly. The advantage of the TransactionScope is that more parties can join the transaction. So not only SqlTransactions, but also transactions from other types. Also a lot of code is taken away when using the transaction scope.
On the other hand, using transaction scope can introduce quite some wierd behavior. Stuff gets escalated to MSDTC in vague situations.
For your situation the transaction scope sounds like the best option. Via this way it is very easy to join multiple actions executed on the
Customer_DALandProduct_DAL, or multiple actions on the same DAL, in a single transaction.Pro’s for SqlTransactions
Con’s for SqlTransaction
Pro’s for TransactionScope
Customer_DALandProduct_DALmixing.Con’s for TransactionScope