mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-04-30 04:45:54 +08:00
Add:
1. Queryable.AsWithAttr() 2. CodeFirst.InitTableWithAttr()
This commit is contained in:
parent
c896b1da5a
commit
34b9a94ba8
@ -45,7 +45,22 @@ namespace SqlSugar
|
||||
DefultLength = length;
|
||||
return this;
|
||||
}
|
||||
|
||||
public void InitTablesWithAttr(params Type[] entityTypes)
|
||||
{
|
||||
foreach (var item in entityTypes)
|
||||
{
|
||||
var attr = item.GetCustomAttribute<TenantAttribute>();
|
||||
if (attr==null||this.Context?.Root == null)
|
||||
{
|
||||
this.Context.CodeFirst.InitTables(item);
|
||||
}
|
||||
else
|
||||
{
|
||||
var newDb = this.Context.Root.GetConnectionWithAttr(item);
|
||||
newDb.CodeFirst.InitTables(item);
|
||||
}
|
||||
}
|
||||
}
|
||||
public virtual void InitTables(Type entityType)
|
||||
{
|
||||
var splitTableAttribute = entityType.GetCustomAttribute<SplitTableAttribute>();
|
||||
|
@ -327,6 +327,12 @@ namespace SqlSugar
|
||||
var entityName = typeof(T).Name;
|
||||
return _As(tableName, entityName);
|
||||
}
|
||||
public ISugarQueryable<T> AsWithAttr()
|
||||
{
|
||||
var asName=GetTableName(this.EntityInfo, this.EntityInfo.DbTableName);
|
||||
this.QueryBuilder.IsCrossQueryWithAttr = true;
|
||||
return this.AS(asName);
|
||||
}
|
||||
public ISugarQueryable<T> AsType(Type tableNameType)
|
||||
{
|
||||
return AS(this.Context.EntityMaintenance.GetEntityInfo(tableNameType).DbTableName);
|
||||
|
@ -16,6 +16,7 @@ namespace SqlSugar
|
||||
void InitTables(string entitiesNamespace);
|
||||
void InitTables(string[] entitiesNamespaces);
|
||||
void InitTables(params Type[] entityTypes);
|
||||
void InitTablesWithAttr(params Type[] entityTypes);
|
||||
void InitTables(Type entityType);
|
||||
void InitTables<T>();
|
||||
void InitTables<T, T2>();
|
||||
|
@ -19,6 +19,7 @@ namespace SqlSugar
|
||||
ISugarQueryable<T> Clone();
|
||||
ISugarQueryable<T> AS<T2>(string tableName);
|
||||
ISugarQueryable<T> AS(string tableName);
|
||||
ISugarQueryable<T> AsWithAttr();
|
||||
ISugarQueryable<T> AsType(Type tableNameType);
|
||||
ISugarQueryable<T> With(string withString);
|
||||
//ISugarQueryable<T> CrossQueryWithAttr();
|
||||
|
@ -875,6 +875,14 @@ namespace SqlSugar
|
||||
var configId = attr.configId;
|
||||
return this.GetConnection(configId);
|
||||
}
|
||||
public SqlSugarProvider GetConnectionWithAttr(Type type)
|
||||
{
|
||||
var attr = type.GetCustomAttribute<TenantAttribute>();
|
||||
if (attr == null)
|
||||
return this.GetConnection(this.CurrentConnectionConfig.ConfigId);
|
||||
var configId = attr.configId;
|
||||
return this.GetConnection(configId);
|
||||
}
|
||||
public SqlSugarScopeProvider GetConnectionScopeWithAttr<T>()
|
||||
{
|
||||
var attr = typeof(T).GetCustomAttribute<TenantAttribute>();
|
||||
|
Loading…
Reference in New Issue
Block a user