using System;
using System.Collections.Generic;
using System.Data;
using System.Data.Common;
using System.Text;
using System.Threading;
using System.Threading.Tasks;
using System.Diagnostics;
using Microsoft.EntityFrameworkCore.Diagnostics;
using YiSha.Util;
namespace YiSha.Data.EF
{
///
/// Sql执行拦截器
///
public class DbCommandCustomInterceptor : DbCommandInterceptor
{
public async override Task> NonQueryExecutingAsync(DbCommand command, CommandEventData eventData, InterceptionResult result, CancellationToken cancellationToken = default)
{
var obj = await base.NonQueryExecutingAsync(command, eventData, result, cancellationToken);
return obj;
}
public async override Task NonQueryExecutedAsync(DbCommand command, CommandExecutedEventData eventData, int result, CancellationToken cancellationToken = default)
{
if (eventData.Duration.TotalMilliseconds >= GlobalContext.SystemConfig.DBSlowSqlLogTime * 1000)
{
LogHelper.Warn("耗时的Sql:" + command.GetCommandText());
}
int val = await base.NonQueryExecutedAsync(command, eventData, result, cancellationToken);
return val;
}
public async override Task> ScalarExecutingAsync(DbCommand command, CommandEventData eventData, InterceptionResult