Pre-Transaction Command in a [Transactional(TransactionalTypes.TransactionScope)] method?

Pre-Transaction Command in a [Transactional(TransactionalTypes.TransactionScope)] method?

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


agartee posted on Wednesday, July 09, 2008

If I have a method that has the "[Transactional(TransactionalTypes.TransactionScope)]" attribute(DataPortal_Insert, DataPortal_Update, DataPortal_Delete) and I want to run a command before the transaction is started (specifically, calling the SQL "sp_setapprole" stored procedure to active a SQL Application Role), how could I go about doing that?

I am trying to keep the code nice and elegant and don't really want to exclude the transaction attribute to handle the transaction myself if I can help it.  Is there something in the CSLA framework that is designed to handle this kind of activity?

ajj3085 replied on Wednesday, July 09, 2008

I think your only option is to handle transactions manually in that case.   You can still use TransactionScope, just not have Csla use the object on your behalf via the attribute.

RockfordLhotka replied on Thursday, July 10, 2008

This is exactly right - if you want more control over the transaction (setting isolation levels for example) or if you want to have some code in the transaction and other code outside the transaction or if you want multiple transactions, then you need to manually set up the transaction yourself.

The good news here is that when it comes to using a TransactionScope, CSLA is only saving you 3 lines of code, two of which are { and }   :)   

I almost didn't even add this support at all - why bother to save such simple code - but it provided parity with the pre-existing model from CSLA 1.x and so I decided to provide the support.

Copyright (c) Marimer LLC