最新消息: USBMI致力于为网友们分享Windows、安卓、IOS等主流手机系统相关的资讯以及评测、同时提供相关教程、应用、软件下载等服务。

利用AOP实现SqlSugar自动事务

IT圈 admin 30浏览 0评论

2024年3月24日发(作者:司空仙仪)

IsAutoCloseConnection = true, //默认false

InitKeyType = Table

});

var key=d().ToString().Replace("-", "");

if (!_nsKey(key))

{

_(key,new SqlClient(client));

_ = key;

return client;

}

throw new Exception("创建SqlSugarClient失败");

}

public static SqlClient GetInstance()

{

var id= _;

if (OrEmpty(id)||!_nsKey(id))

return new SqlClient(CreatInstance());

return _cache[id];

}

public static void Release()

{

try

{

var id = GetId();

if (!_nsKey(id))

return;

Remove(id);

}

catch (Exception e)

{

throw e;

}

}

private static bool Remove(string id)

{

if (!_nsKey(id)) return false;

SqlClient client;

int index = 0;

bool result = false;

while (!(result = _ove(id, out client)))

{

index++;

(20);

if (index > 3) break;

}

return result;

}

private static string GetId()

{

var id = _;

if (OrEmpty(id))

{

throw new Exception("内部错误: SqlSugarClient已丢失.");

}

return id;

}

public static void BeginTran()

{

var instance=GetInstance();

//开启事务

if (!nTran)

{

ran();

nTran = true;

}

}

public static void CommitTran()

{

var id = GetId();

if (!_nsKey(id))

2024年3月24日发(作者:司空仙仪)

IsAutoCloseConnection = true, //默认false

InitKeyType = Table

});

var key=d().ToString().Replace("-", "");

if (!_nsKey(key))

{

_(key,new SqlClient(client));

_ = key;

return client;

}

throw new Exception("创建SqlSugarClient失败");

}

public static SqlClient GetInstance()

{

var id= _;

if (OrEmpty(id)||!_nsKey(id))

return new SqlClient(CreatInstance());

return _cache[id];

}

public static void Release()

{

try

{

var id = GetId();

if (!_nsKey(id))

return;

Remove(id);

}

catch (Exception e)

{

throw e;

}

}

private static bool Remove(string id)

{

if (!_nsKey(id)) return false;

SqlClient client;

int index = 0;

bool result = false;

while (!(result = _ove(id, out client)))

{

index++;

(20);

if (index > 3) break;

}

return result;

}

private static string GetId()

{

var id = _;

if (OrEmpty(id))

{

throw new Exception("内部错误: SqlSugarClient已丢失.");

}

return id;

}

public static void BeginTran()

{

var instance=GetInstance();

//开启事务

if (!nTran)

{

ran();

nTran = true;

}

}

public static void CommitTran()

{

var id = GetId();

if (!_nsKey(id))

发布评论

评论列表 (0)

  1. 暂无评论