mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-11-09 02:44:58 +08:00
Update Core
This commit is contained in:
@@ -87,7 +87,15 @@ namespace SqlSugar
|
|||||||
foreach (var item in properies)
|
foreach (var item in properies)
|
||||||
{
|
{
|
||||||
var value = Activator.CreateInstance(item.PropertyType);
|
var value = Activator.CreateInstance(item.PropertyType);
|
||||||
value.GetType().GetProperty("Context").SetValue(value, this);
|
TenantAttribute tenantAttribute = item.PropertyType.GetGenericArguments()[0].GetCustomAttribute<TenantAttribute>();
|
||||||
|
if (tenantAttribute == null)
|
||||||
|
{
|
||||||
|
value.GetType().GetProperty("Context").SetValue(value, this);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
value.GetType().GetProperty("Context").SetValue(value, this.GetConnection(tenantAttribute.configId));
|
||||||
|
}
|
||||||
item.SetValue(result, value);
|
item.SetValue(result, value);
|
||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
|
|||||||
@@ -1,6 +1,7 @@
|
|||||||
using System;
|
using System;
|
||||||
using System.Collections.Generic;
|
using System.Collections.Generic;
|
||||||
using System.Linq;
|
using System.Linq;
|
||||||
|
using System.Reflection;
|
||||||
using System.Text;
|
using System.Text;
|
||||||
using System.Threading.Tasks;
|
using System.Threading.Tasks;
|
||||||
|
|
||||||
@@ -29,13 +30,30 @@ namespace SqlSugar
|
|||||||
|
|
||||||
public SimpleClient<T> GetRepository<T>() where T : class, new()
|
public SimpleClient<T> GetRepository<T>() where T : class, new()
|
||||||
{
|
{
|
||||||
return new SimpleClient<T>(Db);
|
TenantAttribute tenantAttribute = typeof(T).GetCustomAttribute<TenantAttribute>();
|
||||||
|
if (tenantAttribute == null)
|
||||||
|
{
|
||||||
|
return new SimpleClient<T>(Db);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return new SimpleClient<T>(Db.AsTenant().GetConnection(tenantAttribute.configId));
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public RepositoryType GetMyRepository<RepositoryType>() where RepositoryType : ISugarRepository, new()
|
public RepositoryType GetMyRepository<RepositoryType>() where RepositoryType : ISugarRepository, new()
|
||||||
{
|
{
|
||||||
var result = new RepositoryType();
|
var result = new RepositoryType();
|
||||||
result.Context = this.Db;
|
var type = typeof(RepositoryType).GetGenericArguments()[0];
|
||||||
|
TenantAttribute tenantAttribute = type.GetCustomAttribute<TenantAttribute>();
|
||||||
|
if (tenantAttribute == null)
|
||||||
|
{
|
||||||
|
result.Context = this.Db;
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
result.Context = this.Db.AsTenant().GetConnection(tenantAttribute.configId);
|
||||||
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user