Child DataPortal method calling a Dataportal method with TransactionScope attribute

Child DataPortal method calling a Dataportal method with TransactionScope attribute

Old forum URL: forums.lhotka.net/forums/t/12642.aspx


kreid posted on Friday, May 23, 2014

I have some business objects that can be either root or child objects depending on the context.

Usually I simply call DataPortal_XXX from Child_XXX to avoid duplicate code. Is there any danger of this causing nested transactions due to the transaction scope attribute on the root dataportal function in the calling class?

I could put the "update stuff" into a private function to be safe, but I I am curious whether I need to or not.

Code:

[Transactional(TransactionalTypes.TransactionScope)]

protected override void DataPortal_Update()

 {

        // do update stuff

}

private void Child_Update()

{

        Dataportal_Update();

}

RockfordLhotka replied on Friday, May 23, 2014

The transactions won't nest because that's not how TransactionScope works. The outermost "using TransactionScope" creates the transaction and all other using blocks within that outer using block just reuse the existing transaction. That transaction is committed or rolled back at that top level as the code leaves that outermost using block.

Copyright (c) Marimer LLC