using Microsoft.EntityFrameworkCore.Diagnostics; using System; using System.Data.Common; using System.Threading; using System.Threading.Tasks; namespace UserManagement.Domain { public class TaggedQueryCommandInterceptor : DbCommandInterceptor { public override InterceptionResult ReaderExecuting( DbCommand command, CommandEventData eventData, InterceptionResult result) { ManipulateCommand(command); return result; } public override ValueTask> ReaderExecutingAsync( DbCommand command, CommandEventData eventData, InterceptionResult result, CancellationToken cancellationToken = default) { ManipulateCommand(command); return ValueTask.FromResult(result); } private static void ManipulateCommand(DbCommand command) { if (command.CommandText.StartsWith("-- Use hint: robust plan", StringComparison.Ordinal)) { command.CommandText += " OPTION (ROBUST PLAN)"; } } } }