This commit is contained in:
2881099
2022-04-29 00:05:41 +08:00
parent 4d23d331bc
commit b320d084fa
5 changed files with 57 additions and 27 deletions

View File

@ -159,6 +159,13 @@ namespace base_entity
public DateTime CreateTime { get; set; }
}
class CommandTimeoutCascade : IDisposable
{
public static AsyncLocal<int> _asyncLocalTimeout = new AsyncLocal<int>();
public CommandTimeoutCascade(int timeout) => _asyncLocalTimeout.Value = timeout;
public void Dispose() => _asyncLocalTimeout.Value = 0;
}
static void Main(string[] args)
{
#region IFreeSql
@ -201,6 +208,21 @@ namespace base_entity
BaseEntity.Initialization(fsql, () => _asyncUow.Value);
#endregion
fsql.Aop.CommandBefore += (_, e) =>
{
if (CommandTimeoutCascade._asyncLocalTimeout.Value > 0)
e.Command.CommandTimeout = CommandTimeoutCascade._asyncLocalTimeout.Value;
};
using (new CommandTimeoutCascade(1000))
{
fsql.Select<Order>().ToList();
fsql.Select<Order>().ToList();
fsql.Select<Order>().ToList();
}
fsql.UseJsonMap();
//var txt1 = fsql.Ado.Query<(string, string)>("select '꧁꫞꯭丑小鸭꫞꧂', '123123中国人' from dual");