Synchronization code

This commit is contained in:
sunkaixuan
2023-09-01 19:12:32 +08:00
parent 35e3aa85f7
commit 0d997d2a4d
2 changed files with 14 additions and 4 deletions

View File

@@ -2,6 +2,7 @@
using System.Collections.Generic; using System.Collections.Generic;
using System.Linq; using System.Linq;
using System.Linq.Expressions; using System.Linq.Expressions;
using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -423,8 +424,14 @@ namespace SqlSugar
} }
public IStorageable<T> WhereColumns(Expression<Func<T, object>> columns) public IStorageable<T> WhereColumns(Expression<Func<T, object>> columns)
{ {
if (columns == null) if (columns == null)
return this; return this;
else if (asname == null && typeof(T).GetCustomAttribute<SplitTableAttribute>() != null)
{
whereExpression = columns;
return this;
}
else else
{ {
List<string> list = GetExpressionValue(columns, ResolveExpressType.ArraySingle).GetResultArray().Select(it => Builder.GetNoTranslationColumnName(it)).ToList(); List<string> list = GetExpressionValue(columns, ResolveExpressType.ArraySingle).GetResultArray().Select(it => Builder.GetNoTranslationColumnName(it)).ToList();

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.Linq.Expressions;
using System.Reflection; using System.Reflection;
using System.Text; using System.Text;
using System.Threading.Tasks; using System.Threading.Tasks;
@@ -13,6 +14,8 @@ namespace SqlSugar
internal SqlSugarProvider Context { get; set; } internal SqlSugarProvider Context { get; set; }
internal List<T> List { get; set; } internal List<T> List { get; set; }
internal EntityInfo EntityInfo { get; set; } internal EntityInfo EntityInfo { get; set; }
internal Expression<Func<T, object>> whereExpression { get; set; }
internal int pageSize = 1000; internal int pageSize = 1000;
internal Action<int> ActionCallBack =null; internal Action<int> ActionCallBack =null;
public StorageableSplitProvider<T> PageSize(int size, Action<int> ActionCallBack = null) public StorageableSplitProvider<T> PageSize(int size, Action<int> ActionCallBack = null)
@@ -111,7 +114,7 @@ namespace SqlSugar
foreach (var item in groupModels.GroupBy(it => it.GroupName)) foreach (var item in groupModels.GroupBy(it => it.GroupName))
{ {
var addList = item.Select(it => it.Item).ToList(); var addList = item.Select(it => it.Item).ToList();
resultValue +=await this.Context.Storageable(addList).As(item.Key).ExecuteCommandAsync(); resultValue +=await this.Context.Storageable(addList).As(item.Key).WhereColumns(whereExpression).ExecuteCommandAsync();
if (ActionCallBack != null) if (ActionCallBack != null)
{ {
ActionCallBack(resultValue); ActionCallBack(resultValue);
@@ -128,7 +131,7 @@ namespace SqlSugar
foreach (var item in groupModels.GroupBy(it => it.GroupName)) foreach (var item in groupModels.GroupBy(it => it.GroupName))
{ {
var addList = item.Select(it => it.Item).ToList(); var addList = item.Select(it => it.Item).ToList();
resultValue += this.Context.Storageable(addList).As(item.Key).ExecuteCommand(); resultValue += this.Context.Storageable(addList).As(item.Key).WhereColumns(whereExpression).ExecuteCommand();
} }
return result; return result;
} }
@@ -142,7 +145,7 @@ namespace SqlSugar
foreach (var item in groupModels.GroupBy(it => it.GroupName)) foreach (var item in groupModels.GroupBy(it => it.GroupName))
{ {
var addList = item.Select(it => it.Item).ToList(); var addList = item.Select(it => it.Item).ToList();
resultValue += await this.Context.Storageable(addList).As(item.Key).ExecuteSqlBulkCopyAsync(); resultValue += await this.Context.Storageable(addList).As(item.Key).WhereColumns(whereExpression).ExecuteSqlBulkCopyAsync();
if (ActionCallBack != null) if (ActionCallBack != null)
{ {
ActionCallBack(resultValue); ActionCallBack(resultValue);
@@ -159,7 +162,7 @@ namespace SqlSugar
foreach (var item in groupModels.GroupBy(it => it.GroupName)) foreach (var item in groupModels.GroupBy(it => it.GroupName))
{ {
var addList = item.Select(it => it.Item).ToList(); var addList = item.Select(it => it.Item).ToList();
resultValue += this.Context.Storageable(addList).As(item.Key).ExecuteSqlBulkCopy(); resultValue += this.Context.Storageable(addList).As(item.Key).WhereColumns(whereExpression).ExecuteSqlBulkCopy();
} }
return result; return result;
} }