Table Hints (SQL Server)

Required Nuget Package:
Thinktecture.EntityFrameworkCore.SqlServer

Usage

1. Activate the support for table hints

var services = new ServiceCollection() 
                       .AddDbContext<DemoDbContext>(builder => builder
                               .UseSqlServer("conn-string", 
                                             options => options.AddTableHintSupport());

2. Use extension method WithTableHints

// starts a database transaction
using var rootTx = myDbContext.Database.BeginTransaction();

var product = myDbContext.Products
                         .WithTableHints(SqlServerTableHint.RowLock, SqlServerTableHint.UpdLock)
                         .FirstOrDefaultAsync(p => p.Id == id);