sql - How to use transaction through multiple layer code in C# -


suppose project .net petshop. has bll, dal , sqlhelper.

normally, call bll function in web layer, , bll function calls dal function , finally, dal call sqlhelper.

but in situations, nedd transaction.

for example:

web layer:

i need call bll functions. code below:

var m = bllfunction_1();  var n=  bllfunction_2();  if (m+n<100) { // need rollback here } else { bllfunction_3(); // commit here  } 

so makes me have use transaction object in web layer, pass bll function, , bll layer pass dal layer, , pass sqlhelper.

that's little ugly.

i wonder elegant methed situation.

i assuming looking transaction in ado.net.

basically need wrap "actions" transactionscope.

    try     {         using(transactionscope ts = new transactionscope())         {             //perform sql             using(sqlhelper sh = new sqlhelper())             {                 //do stuff             }              //call new dal function              //call other dal function              ts.complete();                     }     }     catch(exception ex)     {         throw ex;     } 

Comments

Popular posts from this blog

matlab - Deleting rows with specific rules -

jquery - How would i go about shortening this code? And to cancel the previous click on click of new section? -