Update SplitFastest

This commit is contained in:
sunkaixuna
2021-12-17 03:05:58 +08:00
parent ce3a0c71f4
commit b19102d424

View File

@@ -1,6 +1,7 @@
using System; using System;
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -9,7 +10,6 @@ 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 int BulkCopy(List<T> datas) public int BulkCopy(List<T> datas)
{ {
List<GroupModel> groupModels; List<GroupModel> groupModels;
@@ -90,11 +90,14 @@ namespace SqlSugar
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)
{ {
var attribute = typeof(T).GetCustomAttribute<SplitTableAttribute>() as SplitTableAttribute;
Check.Exception(attribute == null, $"{typeof(T).Name} need SplitTableAttribute");
groupModels = new List<GroupModel>(); groupModels = new List<GroupModel>();
var db = FastestProvider.context; var db = FastestProvider.context;
foreach (var item in datas) foreach (var item in datas)
{ {
var tableName = db.SplitHelper<T>().GetTableName(item); var value = db.SplitHelper<T>().GetValue(attribute.SplitType, item);
var tableName = db.SplitHelper<T>().GetTableName(attribute.SplitType,value);
groupModels.Add(new GroupModel() { GroupName = tableName, Item = item }); groupModels.Add(new GroupModel() { GroupName = tableName, Item = item });
} }
result = 0; result = 0;