mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-19 01:58:13 +08:00
Split table support db.Fastest
This commit is contained in:
@@ -69,6 +69,15 @@ namespace OrmTest
|
|||||||
Console.WriteLine();
|
Console.WriteLine();
|
||||||
////强制分表类型
|
////强制分表类型
|
||||||
var x4 = db.Insertable(new OrderSpliteTest() { Name = "A" ,Time=DateTime.Now.AddDays(-1) }).SplitTable().ExecuteCommand();
|
var x4 = db.Insertable(new OrderSpliteTest() { Name = "A" ,Time=DateTime.Now.AddDays(-1) }).SplitTable().ExecuteCommand();
|
||||||
|
|
||||||
|
//分表支持BulkCopy
|
||||||
|
db.Fastest<OrderSpliteTest>().SplitTable().BulkCopy(new List<OrderSpliteTest> {
|
||||||
|
new OrderSpliteTest() { Pk=Guid.NewGuid(),Name ="a", Time = DateTime.Now },
|
||||||
|
new OrderSpliteTest() {Pk=Guid.NewGuid(),Name ="a", Time = DateTime.Now },
|
||||||
|
new OrderSpliteTest() {Pk=Guid.NewGuid(),Name ="a", Time = DateTime.Now.AddMonths(-10) }
|
||||||
|
});
|
||||||
|
|
||||||
|
db.Fastest<OrderSpliteTest>().SplitTable().BulkUpdate(db.Queryable<OrderSpliteTest>().SplitTable(it=>it).ToList());
|
||||||
Console.WriteLine("#### CodeFirst end ####");
|
Console.WriteLine("#### CodeFirst end ####");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@@ -10,6 +10,8 @@ namespace SqlSugar
|
|||||||
public class SplitFastest<T>where T:class,new()
|
public class SplitFastest<T>where T:class,new()
|
||||||
{
|
{
|
||||||
public FastestProvider<T> FastestProvider { get; set; }
|
public FastestProvider<T> FastestProvider { get; set; }
|
||||||
|
public SqlSugarProvider Context { get { return this.FastestProvider.context; } }
|
||||||
|
public EntityInfo EntityInfo { get { return this.Context.EntityMaintenance.GetEntityInfo<T>(); } }
|
||||||
public int BulkCopy(List<T> datas)
|
public int BulkCopy(List<T> datas)
|
||||||
{
|
{
|
||||||
List<GroupModel> groupModels;
|
List<GroupModel> groupModels;
|
||||||
@@ -17,6 +19,7 @@ namespace SqlSugar
|
|||||||
GroupDataList(datas, out groupModels, out result);
|
GroupDataList(datas, out groupModels, out result);
|
||||||
foreach (var item in groupModels.GroupBy(it => it.GroupName))
|
foreach (var item in groupModels.GroupBy(it => it.GroupName))
|
||||||
{
|
{
|
||||||
|
CreateTable(item.Key);
|
||||||
var addList = item.Select(it => it.Item).ToList();
|
var addList = item.Select(it => it.Item).ToList();
|
||||||
result += FastestProvider.AS(item.Key).BulkCopy(addList); ;
|
result += FastestProvider.AS(item.Key).BulkCopy(addList); ;
|
||||||
}
|
}
|
||||||
@@ -29,6 +32,7 @@ namespace SqlSugar
|
|||||||
GroupDataList(datas, out groupModels, out result);
|
GroupDataList(datas, out groupModels, out result);
|
||||||
foreach (var item in groupModels.GroupBy(it => it.GroupName))
|
foreach (var item in groupModels.GroupBy(it => it.GroupName))
|
||||||
{
|
{
|
||||||
|
CreateTable(item.Key);
|
||||||
var addList = item.Select(it => it.Item).ToList();
|
var addList = item.Select(it => it.Item).ToList();
|
||||||
result +=await FastestProvider.AS(item.Key).BulkCopyAsync(addList); ;
|
result +=await FastestProvider.AS(item.Key).BulkCopyAsync(addList); ;
|
||||||
}
|
}
|
||||||
@@ -43,6 +47,7 @@ namespace SqlSugar
|
|||||||
GroupDataList(datas, out groupModels, out result);
|
GroupDataList(datas, out groupModels, out result);
|
||||||
foreach (var item in groupModels.GroupBy(it => it.GroupName))
|
foreach (var item in groupModels.GroupBy(it => it.GroupName))
|
||||||
{
|
{
|
||||||
|
CreateTable(item.Key);
|
||||||
var addList = item.Select(it => it.Item).ToList();
|
var addList = item.Select(it => it.Item).ToList();
|
||||||
result += FastestProvider.AS(item.Key).BulkUpdate(addList); ;
|
result += FastestProvider.AS(item.Key).BulkUpdate(addList); ;
|
||||||
}
|
}
|
||||||
@@ -55,6 +60,7 @@ namespace SqlSugar
|
|||||||
GroupDataList(datas, out groupModels, out result);
|
GroupDataList(datas, out groupModels, out result);
|
||||||
foreach (var item in groupModels.GroupBy(it => it.GroupName))
|
foreach (var item in groupModels.GroupBy(it => it.GroupName))
|
||||||
{
|
{
|
||||||
|
CreateTable(item.Key);
|
||||||
var addList = item.Select(it => it.Item).ToList();
|
var addList = item.Select(it => it.Item).ToList();
|
||||||
result += await FastestProvider.AS(item.Key).BulkUpdateAsync(addList); ;
|
result += await FastestProvider.AS(item.Key).BulkUpdateAsync(addList); ;
|
||||||
}
|
}
|
||||||
@@ -86,7 +92,18 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
return result;
|
return result;
|
||||||
}
|
}
|
||||||
|
private void CreateTable(string tableName)
|
||||||
|
{
|
||||||
|
var isLog = this.Context.Ado.IsEnableLogEvent;
|
||||||
|
this.Context.Ado.IsEnableLogEvent = false;
|
||||||
|
if (!this.Context.DbMaintenance.IsAnyTable(tableName, false))
|
||||||
|
{
|
||||||
|
this.Context.MappingTables.Add(EntityInfo.EntityName, tableName);
|
||||||
|
this.Context.CodeFirst.InitTables<T>();
|
||||||
|
}
|
||||||
|
this.Context.Ado.IsEnableLogEvent = isLog;
|
||||||
|
this.Context.MappingTables.Add(EntityInfo.EntityName, EntityInfo.DbTableName);
|
||||||
|
}
|
||||||
|
|
||||||
private void GroupDataList(List<T> datas, out List<GroupModel> groupModels, out int result)
|
private void GroupDataList(List<T> datas, out List<GroupModel> groupModels, out int result)
|
||||||
{
|
{
|
||||||
|
Reference in New Issue
Block a user