Browse Source

Synchronization code

pull/40/head
sunkaixuan 1 year ago
parent
commit
e5e99d56c8
  1. 17
      Src/Asp.NetCore2/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs
  2. 6
      Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs
  3. 1
      Src/Asp.NetCore2/SqlSugar/Interface/ICodeFirst.cs
  4. 1
      Src/Asp.NetCore2/SqlSugar/Interface/IQueryable.cs
  5. 8
      Src/Asp.NetCore2/SqlSugar/SqlSugarClient.cs

17
Src/Asp.NetCore2/SqlSugar/Abstract/CodeFirstProvider/CodeFirstProvider.cs

@ -45,7 +45,22 @@ namespace SqlSugar
DefultLength = length; DefultLength = length;
return this; 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) public virtual void InitTables(Type entityType)
{ {
var splitTableAttribute = entityType.GetCustomAttribute<SplitTableAttribute>(); var splitTableAttribute = entityType.GetCustomAttribute<SplitTableAttribute>();

6
Src/Asp.NetCore2/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -327,6 +327,12 @@ namespace SqlSugar
var entityName = typeof(T).Name; var entityName = typeof(T).Name;
return _As(tableName, entityName); 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) public ISugarQueryable<T> AsType(Type tableNameType)
{ {
return AS(this.Context.EntityMaintenance.GetEntityInfo(tableNameType).DbTableName); return AS(this.Context.EntityMaintenance.GetEntityInfo(tableNameType).DbTableName);

1
Src/Asp.NetCore2/SqlSugar/Interface/ICodeFirst.cs

@ -16,6 +16,7 @@ namespace SqlSugar
void InitTables(string entitiesNamespace); void InitTables(string entitiesNamespace);
void InitTables(string[] entitiesNamespaces); void InitTables(string[] entitiesNamespaces);
void InitTables(params Type[] entityTypes); void InitTables(params Type[] entityTypes);
void InitTablesWithAttr(params Type[] entityTypes);
void InitTables(Type entityType); void InitTables(Type entityType);
void InitTables<T>(); void InitTables<T>();
void InitTables<T, T2>(); void InitTables<T, T2>();

1
Src/Asp.NetCore2/SqlSugar/Interface/IQueryable.cs

@ -19,6 +19,7 @@ namespace SqlSugar
ISugarQueryable<T> Clone(); ISugarQueryable<T> Clone();
ISugarQueryable<T> AS<T2>(string tableName); ISugarQueryable<T> AS<T2>(string tableName);
ISugarQueryable<T> AS(string tableName); ISugarQueryable<T> AS(string tableName);
ISugarQueryable<T> AsWithAttr();
ISugarQueryable<T> AsType(Type tableNameType); ISugarQueryable<T> AsType(Type tableNameType);
ISugarQueryable<T> With(string withString); ISugarQueryable<T> With(string withString);
//ISugarQueryable<T> CrossQueryWithAttr(); //ISugarQueryable<T> CrossQueryWithAttr();

8
Src/Asp.NetCore2/SqlSugar/SqlSugarClient.cs

@ -875,6 +875,14 @@ namespace SqlSugar
var configId = attr.configId; var configId = attr.configId;
return this.GetConnection(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>() public SqlSugarScopeProvider GetConnectionScopeWithAttr<T>()
{ {
var attr = typeof(T).GetCustomAttribute<TenantAttribute>(); var attr = typeof(T).GetCustomAttribute<TenantAttribute>();

Loading…
Cancel
Save