Skip to content

UnitOfWork for multiple ExecuteAsync stored procedures #6

Description

@james-innes

Look for some help :)

I have multiple stored procedures in MS SQL Server which in themselves are defined as transactions.

In my repository I want to call multiple ExecuteAsync() on stored procedures but for them to be wrapped in a unit of work.

I have managed to implement the transaction for each individual use of ExecuteAsync() but not to wrap them up as a unit pf work.

public async Task UpdateCatName(CatNameUpdateDbModel chat)
        {
            if (cat == null)
                throw new ArgumentNullException(nameof(cat));
// start Unit Of Work
            await _dbClient.ExecuteAsync(DbConstants.SpUpdateCatName,
                new
                {
                    catName = cat.CatName,
                },
                DbConstants.DbConnectionTimeout,
                CommandType.StoredProcedure,
                Transaction);

             await _dbClient.ExecuteAsync(DbConstants.SpUpdateCatNameAuditLog,
                new
                {
                    catNameAuditLog = cat.CatNameAuditLog,
                },
                DbConstants.DbConnectionTimeout,
                CommandType.StoredProcedure,
                Transaction);
// End Unit Of Work
// If either Stored procedure is not successfully completed then bother are rolled back 

     }

Activity

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

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions