diff --git a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs index c055eb489..bcb734e3b 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/InsertableProvider.cs @@ -417,6 +417,8 @@ namespace SqlSugar SplitInsertable result = new SplitInsertable(); result.Context = this.Context; result.EntityInfo = this.EntityInfo; + result.Helper = helper; + result.SplitType = splitType; result.TableNames = new List(); foreach (var item in this.InsertObjs) { diff --git a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/SplitInsertable.cs b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/SplitInsertable.cs index fb3642b61..8fb33b52a 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/SplitInsertable.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/InsertableProvider/SplitInsertable.cs @@ -9,7 +9,9 @@ namespace SqlSugar public class SplitInsertable { public SqlSugarProvider Context; + internal SplitTableContext Helper; public EntityInfo EntityInfo; + public SplitType SplitType; internal IInsertable Inserable { get; set; } internal List TableNames { get; set; } diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index 8b5f5faf3..73f947fc7 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs @@ -836,7 +836,7 @@ namespace SqlSugar } public ISugarQueryable SplitTable(Func, IEnumerable> getTableNamesFunc) { - SplitTableHelper helper = new SplitTableHelper() + SplitTableContext helper = new SplitTableContext() { Context=Context, EntityInfo=this.EntityInfo diff --git a/Src/Asp.Net/SqlSugar/IntegrationServices/SplitTableService.cs b/Src/Asp.Net/SqlSugar/IntegrationServices/SplitTableService.cs index 9fbb3b1b5..da907eb5e 100644 --- a/Src/Asp.Net/SqlSugar/IntegrationServices/SplitTableService.cs +++ b/Src/Asp.Net/SqlSugar/IntegrationServices/SplitTableService.cs @@ -10,7 +10,8 @@ namespace SqlSugar { public class DateSplitTableService : ISplitTableService { - public List GetAllTables(ISqlSugarClient db, EntityInfo EntityInfo,List tableInfos) + #region Core + public List GetAllTables(ISqlSugarClient db, EntityInfo EntityInfo, List tableInfos) { CheckTableName(EntityInfo.DbTableName); var regex = EntityInfo.DbTableName.Replace("{year}", "([0-9]{2,4})").Replace("{day}", "([0-9]{1,2})").Replace("{month}", "([0-9]{1,2})"); @@ -34,30 +35,28 @@ namespace SqlSugar } public string GetTableName(ISqlSugarClient db, EntityInfo EntityInfo) { - return GetTableName(db,EntityInfo,SplitType.Day); + return GetTableName(db, EntityInfo, SplitType.Day); } - - public string GetTableName(ISqlSugarClient db, EntityInfo EntityInfo,SplitType splitType) + public string GetTableName(ISqlSugarClient db, EntityInfo EntityInfo, SplitType splitType) { - var date =db.GetDate(); - return GetTableNameByDate(EntityInfo,splitType,date); + var date = db.GetDate(); + return GetTableNameByDate(EntityInfo, splitType, date); } - public string GetTableName(ISqlSugarClient db, EntityInfo entityInfo, SplitType splitType, object fieldValue) { - var value= Convert.ToDateTime(fieldValue); - return GetTableNameByDate(entityInfo,splitType, value); + var value = Convert.ToDateTime(fieldValue); + return GetTableNameByDate(entityInfo, splitType, value); } public object GetFieldValue(ISqlSugarClient db, EntityInfo entityInfo, SplitType splitType, object entityValue) { - var splitColumn=entityInfo.Columns.FirstOrDefault(it => it.PropertyInfo.PropertyType.GetCustomAttribute()!=null); + var splitColumn = entityInfo.Columns.FirstOrDefault(it => it.PropertyInfo.PropertyType.GetCustomAttribute() != null); if (splitColumn == null) { return db.GetDate(); } - else + else { - var value= splitColumn.PropertyInfo.GetValue(entityValue, null); + var value = splitColumn.PropertyInfo.GetValue(entityValue, null); if (value == null) { return db.GetDate(); @@ -70,13 +69,12 @@ namespace SqlSugar { return db.GetDate(); } - else + else { return value; } } } - public void VerifySplitType(SplitType splitType) { switch (splitType) @@ -92,10 +90,12 @@ namespace SqlSugar case SplitType.Year: break; default: - throw new Exception("DateSplitTableService no support "+ splitType.ToString()); + throw new Exception("DateSplitTableService no support " + splitType.ToString()); } } + #endregion + #region Common Helper private string GetTableNameByDate(EntityInfo EntityInfo,SplitType splitType,DateTime date) { @@ -237,5 +237,14 @@ namespace SqlSugar } #endregion + + #region Private Models + internal class SplitTableSort + { + public string Name { get; set; } + public int Sort { get; set; } + } + #endregion + } } diff --git a/Src/Asp.Net/SqlSugar/SpliteTable/SplitTableContext.cs b/Src/Asp.Net/SqlSugar/SpliteTable/SplitTableContext.cs index d79c7d139..ce12a2c0b 100644 --- a/Src/Asp.Net/SqlSugar/SpliteTable/SplitTableContext.cs +++ b/Src/Asp.Net/SqlSugar/SpliteTable/SplitTableContext.cs @@ -53,7 +53,5 @@ namespace SqlSugar { Check.Exception(EntityInfo.Columns.Any(it => it.IsIdentity == true), ErrorMessage.GetThrowMessage("Split table can't IsIdentity=true", "分表禁止使用自增列")); } - - } } diff --git a/Src/Asp.Net/SqlSugar/SpliteTable/SplitTableInfo.cs b/Src/Asp.Net/SqlSugar/SpliteTable/SplitTableInfo.cs index 30547c205..a9f210c6f 100644 --- a/Src/Asp.Net/SqlSugar/SpliteTable/SplitTableInfo.cs +++ b/Src/Asp.Net/SqlSugar/SpliteTable/SplitTableInfo.cs @@ -16,10 +16,4 @@ namespace SqlSugar public int Int { get; set; } public Byte[] ByteArray { get; set; } } - - internal class SplitTableSort - { - public string Name { get; set; } - public int Sort { get; set; } - } }