For isolation level "ReadUncommitted", we should create a transaction:
using var transaction = await db.Database.BeginTransactionAsync(isolationLevel: System.Data.IsolationLevel.ReadUncommitted);
try
{
// Run the query
await transaction.CommitAsync();
}
catch (Exception)
{
await transaction.RollbackAsync();
}
But xEvent Profiler show this profile login:
This login profile is using "Read Committed"!
According to this question, we have to create two transactions:
using var tran = await db.Database.BeginTransactionAsync(isolationLevel: System.Data.IsolationLevel.ReadUncommitted);
try
{
// without any query
await tran .CommitAsync();
}
catch (Exception)
{
await tran .RollbackAsync();
}
using var transaction = await db.Database.BeginTransactionAsync(isolationLevel: System.Data.IsolationLevel.ReadUncommitted);
try
{
// Run query
await transaction.CommitAsync();
}
catch (Exception)
{
await transaction.RollbackAsync();
}
It does not seem like a good idea to open and close the transaction twice.
How to set the isolation level to "Read Uncommitted" in EF Core?