Browse Source

BulkCopy enable DataAop

pull/33/head
sunkaixuan 2 years ago
parent
commit
60150c6741
  1. 24
      Src/Asp.NetCore2/SqlSugar/Abstract/FastestProvider/FastestProvider.cs
  2. 6
      Src/Asp.NetCore2/SqlSugar/Abstract/FastestProvider/Setting.cs
  3. 1
      Src/Asp.NetCore2/SqlSugar/Interface/IFastest.cs

24
Src/Asp.NetCore2/SqlSugar/Abstract/FastestProvider/FastestProvider.cs

@ -299,6 +299,30 @@ namespace SqlSugar
{
this.context.CurrentConnectionConfig?.AopEvents?.OnLogExecuting($"Begin {title} name:{GetTableName()} ,count: {datas.Count},current time: {DateTime.Now} ", new SugarParameter[] { });
}
var dataEvent = this.context.CurrentConnectionConfig.AopEvents?.DataExecuting;
if (IsDataAop&&dataEvent!=null)
{
var entity = this.context.EntityMaintenance.GetEntityInfo(typeof(Type));
foreach (var item in datas)
{
DataAop(item, isAdd
?
DataFilterType.InsertByObject:
DataFilterType.UpdateByObject
, entity);
}
}
}
private void DataAop<Type>(Type item, DataFilterType type,EntityInfo entity)
{
var dataEvent = this.context.CurrentConnectionConfig.AopEvents?.DataExecuting;
if (dataEvent != null && item != null)
{
foreach (var columnInfo in entity.Columns)
{
dataEvent(columnInfo.PropertyInfo.GetValue(item, null), new DataFilterModel() { OperationType = type, EntityValue = item, EntityColumnInfo = columnInfo });
}
}
}
#endregion

6
Src/Asp.NetCore2/SqlSugar/Abstract/FastestProvider/Setting.cs

@ -13,11 +13,17 @@ namespace SqlSugar
private string CacheKey { get; set; }
private string CacheKeyLike { get; set; }
private string CharacterSet { get; set; }
private bool IsDataAop { get; set; }
public IFastest<T> SetCharacterSet(string CharacterSet)
{
this.CharacterSet = CharacterSet;
return this;
}
public IFastest<T> EnableDataAop()
{
this.IsDataAop = true;
return this;
}
public IFastest<T> RemoveDataCache()
{
CacheKey = typeof(T).FullName;

1
Src/Asp.NetCore2/SqlSugar/Interface/IFastest.cs

@ -13,6 +13,7 @@ namespace SqlSugar
IFastest<T> AS(string tableName);
IFastest<T> PageSize(int Size);
IFastest<T> SetCharacterSet(string CharacterSet);
IFastest<T> EnableDataAop();
int BulkCopy(List<T> datas);
Task<int> BulkCopyAsync(List<T> datas);
int BulkCopy(string tableName,DataTable dataTable);

Loading…
Cancel
Save