db.Fastest Support BulkCopy

This commit is contained in:
sunkaixuna 2021-12-17 02:47:53 +08:00
parent 7d9399fa7e
commit c8b966e025
5 changed files with 68 additions and 2 deletions

View File

@ -8,7 +8,7 @@ namespace SqlSugar
{
public partial class FastestProvider<T>:IFastest<T> where T:class,new()
{
private SqlSugarProvider context;
internal SqlSugarProvider context;
private ISugarQueryable<T> queryable;
private EntityInfo entityInfo { get; set; }
public bool isLog;

View File

@ -21,5 +21,11 @@ namespace SqlSugar
this.Size = size;
return this;
}
public SplitFastest<T> SplitTable()
{
SplitFastest<T> result = new SplitFastest<T>();
result.FastestProvider = this;
return result;
}
}
}

View File

@ -0,0 +1,57 @@
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace SqlSugar
{
public class SplitFastest<T>where T:class,new()
{
public FastestProvider<T> FastestProvider { get; set; }
public int BulkCopy(List<T> datas)
{
List<GroupModel> groupModels;
int result;
GroupDataList(datas, out groupModels, out result);
foreach (var item in groupModels.GroupBy(it => it.GroupName))
{
var addList = item.Select(it => it.Item).ToList();
result += FastestProvider.BulkCopy(addList); ;
}
return result;
}
public async Task<int> BulkCopyAsync(List<T> datas)
{
List<GroupModel> groupModels;
int result;
GroupDataList(datas, out groupModels, out result);
foreach (var item in groupModels.GroupBy(it => it.GroupName))
{
var addList = item.Select(it => it.Item).ToList();
result +=await FastestProvider.BulkCopyAsync(addList); ;
}
return result;
}
private void GroupDataList(List<T> datas, out List<GroupModel> groupModels, out int result)
{
groupModels = new List<GroupModel>();
var db = FastestProvider.context;
foreach (var item in datas)
{
var tableName = db.SplitHelper<T>().GetTableName(item);
groupModels.Add(new GroupModel() { GroupName = tableName, Item = item });
}
result = 0;
}
public class GroupModel
{
public string GroupName { get; set; }
public T Item { get; set; }
}
}
}

View File

@ -5,7 +5,7 @@ using System.Threading.Tasks;
namespace SqlSugar
{
public interface IFastest<T>
public interface IFastest<T> where T:class,new()
{
IFastest<T> AS(string tableName);
IFastest<T> PageSize(int Size);
@ -16,5 +16,7 @@ namespace SqlSugar
Task<int> BulkUpdateAsync(List<T> datas);
int BulkUpdate(List<T> datas, string[] whereColumns, string[] updateColumns);
Task<int> BulkUpdateAsync(List<T> datas, string[] whereColumns, string[] updateColumns);
SplitFastest<T> SplitTable();
}
}

View File

@ -92,6 +92,7 @@
<Compile Include="Abstract\FastestProvider\FastestProvider.cs" />
<Compile Include="Abstract\FastestProvider\Private.cs" />
<Compile Include="Abstract\FastestProvider\Setting.cs" />
<Compile Include="Abstract\FastestProvider\SplitFastest.cs" />
<Compile Include="Abstract\FilterProvider\FilterProvider.cs" />
<Compile Include="Abstract\SugarProvider\SqlSugarCoreProvider.cs" />
<Compile Include="Interface\IFastBuilder.cs" />