Skip to content

dapper.rainbow external transaction support #1944

Closed

Description

@kbilsted

How to best use Dapper.rainbow code with transactions? For example, I may do operations that are not supported by dapper.rainbow in the same transaction as dapper.rainbow operations.

Dapper.rainbow Database class has a field private DbTransaction _transaction; that cannot be accessed. This means there is no way to "enlist" the rainbow database in an existing transaction.

There is a method void BeginTransaction() which allows me to create a new transaction. But since it is not returned, I cannot piggyback on top of it.

I was thinking that maybe we need to extend the code base.

  • Either by making an overload of Init() taking a transaction parameter from which the transaction and the connection can be accessed.
  • or by creating a method void EnlistTransaction(DbTransaction tx) { _dbTransaction = tx; }
  • Or maybe just expose the transaction variable. The very least make it protected such that subclasses can access it.

Will this be acceptable? I'm happy to create a pull request if we can agree on a design.

Activity

  1. kbilsted commented on Feb 3, 2024

    @kbilsted
    ContributorAuthor

    Any news on this?

  2. mgravell commented on Feb 3, 2024

    @mgravell
    Member

    K, sorry - lots of spinning plates. In principal, I'm fine with both exposing the transaction as a property, and with offering an enlist method. The second has caveats, though :

    • what happens if you enlist when there is already a transaction?
    • what happens if you begin /commit a transaction via rainbow after enlisting?
    • etc

    If those things act appropriately (probably by throwing invalid operation exception), then: great!

  3. added a commit that references this issue on Feb 5, 2024
    128037e
  4. kbilsted commented on Feb 7, 2024

    @kbilsted
    ContributorAuthor

    The build pipeline is failing on installing dependencies so it cannot run the tests

  5. added 3 commits that reference this issue on Feb 11, 2024
    11ebdae
    15cc99a
    e0a1bcc
  6. added a commit that references this issue on Feb 15, 2024
    4f8e92f
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions