mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-05-17 21:49:33 +08:00
db.Fastest Support BulkCopy
This commit is contained in:
parent
7d9399fa7e
commit
c8b966e025
@ -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;
|
||||
|
@ -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;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -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; }
|
||||
}
|
||||
}
|
||||
|
||||
}
|
@ -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();
|
||||
}
|
||||
}
|
||||
|
@ -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" />
|
||||
|
Loading…
Reference in New Issue
Block a user