mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
@ -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");
|
||||
|
Reference in New Issue
Block a user