using MES.Service.util;
|
using SqlSugar;
|
|
namespace MES.Service.DB;
|
|
public class RepositoryNoEntity
|
{
|
protected static SqlSugarScope Db = new(new ConnectionConfig
|
{
|
DbType = DbType.Oracle,
|
ConnectionString = AppsettingsUtility.Settings.DataBaseConn,
|
IsAutoCloseConnection = true
|
},
|
db =>
|
{
|
db.Aop.OnLogExecuting = (sql, pars) =>
|
{
|
Console.WriteLine(
|
UtilMethods.GetSqlString(DbType.Oracle, sql, pars));
|
};
|
});
|
|
|
protected int UseTransaction(Func<SqlSugarScope, int> action)
|
{
|
try
|
{
|
Db.Ado.BeginTran(); // 开始事务
|
var affectedRows = action.Invoke(Db); // 执行传入的操作并获取受影响的行数
|
Db.Ado.CommitTran(); // 提交事务
|
return affectedRows; // 返回受影响的行数
|
}
|
catch (Exception)
|
{
|
Db.Ado.RollbackTran(); // 回滚事务
|
throw; // 重新抛出异常
|
}
|
}
|
}
|