Browse Source

Optimize split table

pull/12/head
sunkaixuna 3 years ago
parent
commit
b8da23f9e7
  1. 3
      Src/Asp.Net/MySqlTest/Demo/DemoN_SplitTable.cs
  2. 4
      Src/Asp.Net/PgSqlTest/Demo/DemoN_SplitTable.cs
  3. 5
      Src/Asp.Net/SqlServerTest/Demo/DemoN_SplitTable.cs
  4. 14
      Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

3
Src/Asp.Net/MySqlTest/Demo/DemoN_SplitTable.cs

@ -68,6 +68,9 @@ namespace OrmTest
Console.WriteLine();
////强制分表类型
var x4 = db.Insertable(new OrderSpliteTest() { Name = "A" ,Time=DateTime.Now.AddDays(-1) }).SplitTable().ExecuteCommand();
var tableName21 = db.SplitHelper<OrderSpliteTest>().GetTableName(DateTime.Now.AddDays(-111));
var listNull = db.Queryable<OrderSpliteTest>().SplitTable(ta => ta.InTableNames(tableName21)).ToList();
Console.WriteLine("#### CodeFirst end ####");
}

4
Src/Asp.Net/PgSqlTest/Demo/DemoN_SplitTable.cs

@ -68,6 +68,10 @@ namespace OrmTest
Console.WriteLine();
////强制分表类型
var x4 = db.Insertable(new OrderSpliteTest() { Name = "A" ,Time=DateTime.Now.AddDays(-1) }).SplitTable().ExecuteCommand();
var tableName21 = db.SplitHelper<OrderSpliteTest>().GetTableName(DateTime.Now.AddDays(-111));
var listNull = db.Queryable<OrderSpliteTest>().SplitTable(ta => ta.InTableNames(tableName21)).ToList();
Console.WriteLine("#### CodeFirst end ####");
}

5
Src/Asp.Net/SqlServerTest/Demo/DemoN_SplitTable.cs

@ -48,7 +48,10 @@ namespace OrmTest
Console.WriteLine();
var tableName = db.SplitHelper<OrderSpliteTest>().GetTableName(DateTime.Now.AddDays(-1));
var tableName = db.SplitHelper<OrderSpliteTest>().GetTableName(DateTime.Now.AddDays(-111));
var listNull= db.Queryable<OrderSpliteTest>().SplitTable(ta => ta.InTableNames(tableName)).ToList();
var tableName2 = db.SplitHelper(new OrderSpliteTest() { Time=DateTime.Now}).GetTableNames();
var tableName3 = db.SplitHelper(new List<OrderSpliteTest> {
new OrderSpliteTest() { Time = DateTime.Now },

14
Src/Asp.Net/SqlSugar/Abstract/QueryableProvider/QueryableProvider.cs

@ -931,11 +931,19 @@ namespace SqlSugar
{
tableQueryables.Add(this.Clone().AS(item.TableName));
}
Check.Exception(tableQueryables.Count == 0, ErrorMessage.GetThrowMessage("SplitTable error . There are no tables after filtering", "SplitTable没有筛选出分表,请检查条件和数据库中的表"));
var unionall = this.Context._UnionAll(tableQueryables.ToArray());
if (tableQueryables.Count == 0)
{
var result= this.Context.SqlQueryable<object>("-- No table ").Select<T>();
result.QueryBuilder.SelectValue = null;
return result;
}
else
{
var unionall = this.Context._UnionAll(tableQueryables.ToArray());
return unionall;
}
//var values= unionall.QueryBuilder.GetSelectValue;
//unionall.QueryBuilder.SelectValue = values;
return unionall;
}
public ISugarQueryable<T> Distinct()
{

Loading…
Cancel
Save