mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-12-26 14:15:50 +08:00
Update split table with sqlserver schema
This commit is contained in:
@@ -665,6 +665,10 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Private
|
||||
public virtual List<DbTableInfo> GetSchemaTables(EntityInfo entityInfo)
|
||||
{
|
||||
return null;
|
||||
}
|
||||
protected List<T> GetListOrCache<T>(string cacheKey, string sql)
|
||||
{
|
||||
return this.Context.Utilities.GetReflectionInoCacheInstance().GetOrCreate(cacheKey,
|
||||
|
||||
@@ -321,6 +321,28 @@ namespace SqlSugar
|
||||
#endregion
|
||||
|
||||
#region Methods
|
||||
public override List<DbTableInfo> GetSchemaTables(EntityInfo entityInfo)
|
||||
{
|
||||
if (entityInfo.DbTableName.Contains(".") && this.Context.CurrentConnectionConfig.DbType == DbType.SqlServer)
|
||||
{
|
||||
var schema = entityInfo.DbTableName.Split('.').First();
|
||||
var isAny = GetSchemas().Any(it => it.EqualCase(schema))||schema.EqualCase("dbo");
|
||||
if (isAny)
|
||||
{
|
||||
var tableInfos = this.Context.Ado.SqlQuery<DbTableInfo>(@"SELECT schem.name+'.'+tb.name Name,tb.Description from
|
||||
( SELECT obj.name,Convert(nvarchar(max),prop.value)as Description,obj.schema_id FROM sys.objects obj
|
||||
LEFT JOIN sys.extended_properties prop
|
||||
ON obj.object_id=prop.major_id
|
||||
and prop.minor_id=0
|
||||
AND (prop.Name='MS_Description' OR prop.Name is null)
|
||||
WHERE obj.type IN('U')) tb
|
||||
inner join sys.schemas as schem
|
||||
on tb.schema_id=schem.schema_id ");
|
||||
return tableInfos;
|
||||
}
|
||||
}
|
||||
return null;
|
||||
}
|
||||
public override List<string> GetDbTypes()
|
||||
{
|
||||
return this.Context.Ado.SqlQuery<string>(@"SELECT name
|
||||
|
||||
@@ -58,14 +58,18 @@ namespace SqlSugar
|
||||
}
|
||||
public List<SplitTableInfo> GetTables()
|
||||
{
|
||||
if (StaticConfig.SplitTableGetTablesFunc != null)
|
||||
if (StaticConfig.SplitTableGetTablesFunc != null)
|
||||
{
|
||||
return StaticConfig.SplitTableGetTablesFunc();
|
||||
}
|
||||
var oldIsEnableLogEvent = this.Context.Ado.IsEnableLogEvent;
|
||||
this.Context.Ado.IsEnableLogEvent = false;
|
||||
var tableInfos = this.Context.DbMaintenance.GetTableInfoList(false);
|
||||
List<SplitTableInfo> result = Service.GetAllTables(this.Context,EntityInfo,tableInfos);
|
||||
List<DbTableInfo> tableInfos =((DbMaintenanceProvider)this.Context.DbMaintenance).GetSchemaTables(EntityInfo);
|
||||
if (tableInfos == null)
|
||||
{
|
||||
tableInfos = this.Context.DbMaintenance.GetTableInfoList(false);
|
||||
}
|
||||
List<SplitTableInfo> result = Service.GetAllTables(this.Context, EntityInfo, tableInfos);
|
||||
this.Context.Ado.IsEnableLogEvent = oldIsEnableLogEvent;
|
||||
return result;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user