diff --git a/Src/Asp.Net/SqlServerTest/Demo/DemoN_SplitTable.cs b/Src/Asp.Net/SqlServerTest/Demo/DemoN_SplitTable.cs index fc89f8458..216017fe6 100644 --- a/Src/Asp.Net/SqlServerTest/Demo/DemoN_SplitTable.cs +++ b/Src/Asp.Net/SqlServerTest/Demo/DemoN_SplitTable.cs @@ -25,11 +25,18 @@ namespace OrmTest Console.WriteLine(s); }; + //初始化分表 db.CodeFirst.SplitTables().InitTables(); - var list=db.Queryable().SplitTable(tabs => tabs.Take(3)).ToList(); + //根据最近3个表进行查询 + var list=db.Queryable().Where(it=>it.Pk==Guid.NewGuid()) + .SplitTable(tabs => tabs.Take(3)) + .Where(it=>it.Time==DateTime.Now).ToOffsetPage(1,2); + + //根据时间选出的表进行查询 var list2 = db.Queryable().SplitTable(tabs => tabs.Where(it=> it.Date>=DateTime.Now.AddYears(-2))).ToList(); + //删除数据只在最近3张表执行操作 var x = db.Deleteable().Where(it=>it.Pk==Guid.NewGuid()).SplitTable(tabs => tabs.Take(3)).ExecuteCommand(); var x2 = db.Updateable() @@ -38,7 +45,9 @@ namespace OrmTest .SplitTable(tabs => tabs.Take(3)) .ExecuteCommand(); + //按日分表 var x3 = db.Insertable(new OrderSpliteTest() { Name="A" }).SplitTable(SplitType.Day).ExecuteCommand(); + //按日分表,根据time字段扔到对应的表中 var x4 = db.Insertable(new OrderSpliteTest() { Name = "A" }).SplitTable(SplitType.Day,it=>it.Time).ExecuteCommand(); Console.WriteLine("#### CodeFirst end ####"); } diff --git a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs index 0d7d55855..8b5f5faf3 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs @@ -843,13 +843,15 @@ namespace SqlSugar }; this.Context.MappingTables.Add(this.EntityInfo.EntityName, this.EntityInfo.DbTableName); var tables = getTableNamesFunc(helper.GetTables()); - List> tableQueryables = new List>(); + List> tableQueryables = new List>(); foreach (var item in tables) { - tableQueryables.Add(this.Context.Queryable().AS(item.TableName)); + tableQueryables.Add(this.Clone().AS(item.TableName)); } - var asName = this.Context.UnionAll(tableQueryables.ToArray()).QueryBuilder.GetTableNameString; - return this.AS(asName); + var unionall = this.Context._UnionAll(tableQueryables.ToArray()); + //var values= unionall.QueryBuilder.GetSelectValue; + //unionall.QueryBuilder.SelectValue = values; + return unionall; } public ISugarQueryable Distinct() { diff --git a/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs b/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs index daaf5b60b..751664bd2 100644 --- a/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs +++ b/Src/Asp.Net/SqlSugar/Abstract/SugarProvider/SqlSugarProvider.cs @@ -504,6 +504,11 @@ namespace SqlSugar #endregion public virtual ISugarQuerya