mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-11-10 03:14:57 +08:00
Split table
This commit is contained in:
@@ -24,9 +24,12 @@ namespace OrmTest
|
|||||||
{
|
{
|
||||||
Console.WriteLine(s);
|
Console.WriteLine(s);
|
||||||
};
|
};
|
||||||
|
|
||||||
db.CodeFirst.SplitTables().InitTables<OrderSpliteTest>();
|
db.CodeFirst.SplitTables().InitTables<OrderSpliteTest>();
|
||||||
var list=db.Queryable<OrderSpliteTest>().SplitTable(tabs => tabs.Take(3)).ToList();
|
var list=db.Queryable<OrderSpliteTest>().SplitTable(tabs => tabs.Take(3)).ToList();
|
||||||
|
|
||||||
|
var list2 = db.Queryable<OrderSpliteTest>().SplitTable(tabs => tabs.Where(it=> it.Date>=DateTime.Now.AddYears(-2))).ToList();
|
||||||
|
|
||||||
var x = db.Deleteable<OrderSpliteTest>().Where(it=>it.Pk==Guid.NewGuid()).SplitTable(tabs => tabs.Take(3)).ExecuteCommand();
|
var x = db.Deleteable<OrderSpliteTest>().Where(it=>it.Pk==Guid.NewGuid()).SplitTable(tabs => tabs.Take(3)).ExecuteCommand();
|
||||||
|
|
||||||
var x2 = db.Updateable<OrderSpliteTest>()
|
var x2 = db.Updateable<OrderSpliteTest>()
|
||||||
@@ -34,6 +37,9 @@ namespace OrmTest
|
|||||||
.Where(it => it.Pk == Guid.NewGuid())
|
.Where(it => it.Pk == Guid.NewGuid())
|
||||||
.SplitTable(tabs => tabs.Take(3))
|
.SplitTable(tabs => tabs.Take(3))
|
||||||
.ExecuteCommand();
|
.ExecuteCommand();
|
||||||
|
|
||||||
|
var x3 = db.Insertable(new OrderSpliteTest() { Name="A" }).SplitTable(SplitType.Day).ExecuteCommand();
|
||||||
|
var x4 = db.Insertable(new OrderSpliteTest() { Name = "A" }).SplitTable(SplitType.Day,it=>it.Time).ExecuteCommand();
|
||||||
Console.WriteLine("#### CodeFirst end ####");
|
Console.WriteLine("#### CodeFirst end ####");
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -43,6 +49,8 @@ namespace OrmTest
|
|||||||
[SugarColumn(IsPrimaryKey =true)]
|
[SugarColumn(IsPrimaryKey =true)]
|
||||||
public Guid Pk{ get; set; }
|
public Guid Pk{ get; set; }
|
||||||
public string Name { get; set; }
|
public string Name { get; set; }
|
||||||
|
[SugarColumn(IsNullable =true)]
|
||||||
|
public DateTime Time { get; set; }
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -406,6 +406,20 @@ namespace SqlSugar
|
|||||||
result.AddSubList(tree);
|
result.AddSubList(tree);
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
public SplitInsertable SplitTable(SplitType splitType)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SplitInsertable SplitTable(SplitType splitType, Expression<Func<T, DateTime>> splitFieldName)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
|
public SplitInsertable SplitTable(SplitType splitType, Expression<Func<T, DateTime?>> splitFieldName)
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
|
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
|||||||
@@ -8,6 +8,9 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public class SplitInsertable
|
public class SplitInsertable
|
||||||
{
|
{
|
||||||
|
public object ExecuteCommand()
|
||||||
|
{
|
||||||
|
throw new NotImplementedException();
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -46,7 +46,9 @@ namespace SqlSugar
|
|||||||
MySqlBlukCopy<T> UseMySql();
|
MySqlBlukCopy<T> UseMySql();
|
||||||
OracleBlukCopy UseOracle();
|
OracleBlukCopy UseOracle();
|
||||||
|
|
||||||
//SplitInsertable SplitTable(SplitType splitType);
|
SplitInsertable SplitTable(SplitType splitType);
|
||||||
|
SplitInsertable SplitTable(SplitType splitType,Expression<Func<T,DateTime>> splitFieldName);
|
||||||
|
SplitInsertable SplitTable(SplitType splitType, Expression<Func<T, DateTime?>> splitFieldName);
|
||||||
|
|
||||||
void AddQueue();
|
void AddQueue();
|
||||||
|
|
||||||
|
|||||||
@@ -11,6 +11,39 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
public SqlSugarProvider Context { get; set; }
|
public SqlSugarProvider Context { get; set; }
|
||||||
public EntityInfo EntityInfo { get; set; }
|
public EntityInfo EntityInfo { get; set; }
|
||||||
|
public DateTime GetTableGetDate(DateTime time,SplitType type)
|
||||||
|
{
|
||||||
|
switch (type)
|
||||||
|
{
|
||||||
|
case SplitType.Day:
|
||||||
|
return Convert.ToDateTime(time.ToString("yyyy-MM-dd"));
|
||||||
|
case SplitType.Week:
|
||||||
|
return GetMondayDate(time);
|
||||||
|
case SplitType.Month:
|
||||||
|
return Convert.ToDateTime(time.ToString("yyyy-MM-01"));
|
||||||
|
case SplitType.Season:
|
||||||
|
if (time.Month <= 3)
|
||||||
|
{
|
||||||
|
return Convert.ToDateTime(time.ToString("yyyy-01-01"));
|
||||||
|
}
|
||||||
|
else if (time.Month <= 6)
|
||||||
|
{
|
||||||
|
return Convert.ToDateTime(time.ToString("yyyy-04-01"));
|
||||||
|
}
|
||||||
|
else if (time.Month <= 9)
|
||||||
|
{
|
||||||
|
return Convert.ToDateTime(time.ToString("yyyy-07-01"));
|
||||||
|
}
|
||||||
|
else
|
||||||
|
{
|
||||||
|
return Convert.ToDateTime(time.ToString("yyyy-10-01"));
|
||||||
|
}
|
||||||
|
case SplitType.Year:
|
||||||
|
return Convert.ToDateTime(time.ToString("yyyy-01-01"));
|
||||||
|
default:
|
||||||
|
throw new Exception($"SplitType paramter error ");
|
||||||
|
}
|
||||||
|
}
|
||||||
public List<SplitTableInfo> GetTables()
|
public List<SplitTableInfo> GetTables()
|
||||||
{
|
{
|
||||||
|
|
||||||
@@ -120,5 +153,30 @@ namespace SqlSugar
|
|||||||
Check.Exception(Regex.IsMatch(dbTableName, @"\d\{|\}\d"), ErrorMessage.GetThrowMessage(" '{{' or '}}' can't be numbers nearby", "占位符相令一位不能是数字,比如 : 1{{day}}2 错误 , 正确: 1_{{day}}_2"));
|
Check.Exception(Regex.IsMatch(dbTableName, @"\d\{|\}\d"), ErrorMessage.GetThrowMessage(" '{{' or '}}' can't be numbers nearby", "占位符相令一位不能是数字,比如 : 1{{day}}2 错误 , 正确: 1_{{day}}_2"));
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
|
#region 得到一周的周一和周日的日期
|
||||||
|
public static DateTime GetMondayDate()
|
||||||
|
{
|
||||||
|
return GetMondayDate(DateTime.Now);
|
||||||
|
}
|
||||||
|
public static DateTime GetSundayDate()
|
||||||
|
{
|
||||||
|
return GetSundayDate(DateTime.Now);
|
||||||
|
}
|
||||||
|
public static DateTime GetMondayDate(DateTime someDate)
|
||||||
|
{
|
||||||
|
int i = someDate.DayOfWeek - DayOfWeek.Monday;
|
||||||
|
if (i == -1) i = 6;
|
||||||
|
TimeSpan ts = new TimeSpan(i, 0, 0, 0);
|
||||||
|
return someDate.Subtract(ts);
|
||||||
|
}
|
||||||
|
public static DateTime GetSundayDate(DateTime someDate)
|
||||||
|
{
|
||||||
|
int i = someDate.DayOfWeek - DayOfWeek.Sunday;
|
||||||
|
if (i != 0) i = 7 - i;
|
||||||
|
TimeSpan ts = new TimeSpan(i, 0, 0, 0);
|
||||||
|
return someDate.Add(ts);
|
||||||
|
}
|
||||||
|
#endregion
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,6 +10,8 @@ namespace SqlSugar
|
|||||||
{
|
{
|
||||||
Day=0,
|
Day=0,
|
||||||
Week=1,
|
Week=1,
|
||||||
Month=1
|
Month =2,
|
||||||
|
Season=3,
|
||||||
|
Year=4
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user