Table of Contents

Class SqlServerTransactionLock

Namespace
NuvTools.Data.EntityFrameworkCore.SqlServer.Context
Assembly
NuvTools.Data.EntityFrameworkCore.SqlServer.dll

SQL Server implementation of IDbContextTransactionLock, on top of sp_getapplock with @LockOwner = 'Transaction': blocks until the lock is granted and releases it when the transaction ends.

public sealed class SqlServerTransactionLock : IDbContextTransactionLock
Inheritance
SqlServerTransactionLock
Implements
Inherited Members

Remarks

SQL Server keys application locks by the resource name itself, so the caller's name is used as given — only names longer than the 255 characters it accepts are replaced by a hash.

Methods

AcquireAsync(DbContext, string, CancellationToken)

Acquires the exclusive lock named name, blocking until it is granted, and holds it until the current transaction of context ends.

public Task AcquireAsync(DbContext context, string name, CancellationToken cancellationToken = default)

Parameters

context DbContext

The context whose transaction and connection the lock belongs to.

name string

Lock name, as given by the caller.

cancellationToken CancellationToken

A cancellation token to observe while waiting for the task to complete.

Returns

Task

A task that completes once the lock is held.