mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-01 10:10:16 +08:00
Add db.GetConnectionWithAttr
This commit is contained in:
parent
7982e5aa03
commit
06d4f13599
@ -21,6 +21,7 @@ namespace SqlSugar
|
||||
Task<DbResult<T>> UseTranAsync<T>(Func<Task<T>> action, Action<Exception> errorCallBack = null);
|
||||
void AddConnection(ConnectionConfig connection);
|
||||
SqlSugarProvider GetConnection(dynamic configId);
|
||||
SqlSugarProvider GetConnectionWithAttr<T>();
|
||||
bool IsAnyConnection(dynamic configId);
|
||||
|
||||
void Close();
|
||||
|
@ -5,6 +5,7 @@ using System.Diagnostics;
|
||||
using System.Dynamic;
|
||||
using System.Linq;
|
||||
using System.Linq.Expressions;
|
||||
using System.Reflection;
|
||||
using System.Text;
|
||||
using System.Threading;
|
||||
using System.Threading.Tasks;
|
||||
@ -633,6 +634,13 @@ namespace SqlSugar
|
||||
});
|
||||
}
|
||||
}
|
||||
public SqlSugarProvider GetConnectionWithAttr<T>()
|
||||
{
|
||||
var attr = typeof(T).GetCustomAttribute<TenantAttribute>();
|
||||
Check.ExceptionEasy("not TenantAttribute", "不存在特性 TenantAttribute");
|
||||
var configId = attr.configId;
|
||||
return this.GetConnection(configId);
|
||||
}
|
||||
public SqlSugarProvider GetConnection(dynamic configId)
|
||||
{
|
||||
InitTenant();
|
||||
|
@ -158,6 +158,10 @@ namespace SqlSugar
|
||||
{
|
||||
return ScopedContext.GetConnection(configId);
|
||||
}
|
||||
public SqlSugarProvider GetConnectionWithAttr<T>()
|
||||
{
|
||||
return ScopedContext.GetConnectionWithAttr<T>();
|
||||
}
|
||||
|
||||
public DateTime GetDate()
|
||||
{
|
||||
|
@ -29,5 +29,9 @@ namespace SqlSugar
|
||||
if (isException)
|
||||
throw new SqlSugarException(string.Format(message, args));
|
||||
}
|
||||
public static void ExceptionEasy(string enMessage, string cnMessage)
|
||||
{
|
||||
throw new SqlSugarException(ErrorMessage.GetThrowMessage(enMessage, cnMessage));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user