DapperRepository icon indicating copy to clipboard operation
DapperRepository copied to clipboard

How can I Use transaction?

Open andruska1994 opened this issue 3 years ago • 1 comments

Great repository. Truly exceptional. Thanks.

I have a request. How do I use transactions in the "service layer"? For example: I have a "UserService" and one method performs two inserts that are dependent on each other. My need is to cancel the first entry in case the second goes wrong and rollback transaction. I noticed that the transaction logic is implemented in the Repository layer, but this way how can I use them.? The only thing I can do at the moment is passing a param "useTransaction". If is true it uses transaction but that's not what I need.

Best regards

andruska1994 avatar May 25 '22 15:05 andruska1994

Great repository. Truly exceptional. Thanks.

I have a request. How do I use transactions in the "service layer"? For example: I have a "UserService" and one method performs two inserts that are dependent on each other. My need is to cancel the first entry in case the second goes wrong and rollback transaction. I noticed that the transaction logic is implemented in the Repository layer, but this way how can I use them.? The only thing I can do at the moment is passing a param "useTransaction". If is true it uses transaction but that's not what I need.

Best regards

Sorry I just saw now, first of all, I don't recommend that you do transactional operations in the service layer, which is not conducive to code management, and it is very easy to do it in the Data layer. But if you must,

  1. You can use TransactionScope, but it doesn't have a rollback mechanism
  2. I can help you modify the code remotely to implement the service layer using database transactions

Olek-HZQ avatar Jun 20 '22 03:06 Olek-HZQ