mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-24 04:53:45 +08:00
Performance optimization
This commit is contained in:
@@ -353,6 +353,40 @@ namespace SqlSugar
|
|||||||
#endregion
|
#endregion
|
||||||
|
|
||||||
#region Private methods
|
#region Private methods
|
||||||
|
private void _ThenMapper<T>(IEnumerable<T> list, Action<T> action)
|
||||||
|
{
|
||||||
|
MapperContext<T> result = new MapperContext<T>();
|
||||||
|
result.context = this.Context;
|
||||||
|
if (result.context.TempItems == null)
|
||||||
|
{
|
||||||
|
result.context.TempItems = new Dictionary<string, object>();
|
||||||
|
}
|
||||||
|
var key = "Queryable_To_Context";
|
||||||
|
result.context.TempItems.Add(key, result);
|
||||||
|
result.list = list.ToList();
|
||||||
|
foreach (var item in list)
|
||||||
|
{
|
||||||
|
action.Invoke(item);
|
||||||
|
}
|
||||||
|
result.context.TempItems.Remove(key);
|
||||||
|
}
|
||||||
|
private async Task _ThenMapperAsync<T>(IEnumerable<T> list, Func<T, Task> action)
|
||||||
|
{
|
||||||
|
MapperContext<T> result = new MapperContext<T>();
|
||||||
|
result.context = this.Context;
|
||||||
|
if (result.context.TempItems == null)
|
||||||
|
{
|
||||||
|
result.context.TempItems = new Dictionary<string, object>();
|
||||||
|
}
|
||||||
|
var key = "Queryable_To_Context";
|
||||||
|
result.context.TempItems.Add(key, result);
|
||||||
|
result.list = list.ToList();
|
||||||
|
foreach (var item in list)
|
||||||
|
{
|
||||||
|
await action.Invoke(item);
|
||||||
|
}
|
||||||
|
result.context.TempItems.Remove(key);
|
||||||
|
}
|
||||||
internal string GetN()
|
internal string GetN()
|
||||||
{
|
{
|
||||||
var N = "N";
|
var N = "N";
|
||||||
|
@@ -1665,37 +1665,18 @@ namespace SqlSugar
|
|||||||
}
|
}
|
||||||
public void ThenMapper<T>(IEnumerable<T> list, Action<T> action)
|
public void ThenMapper<T>(IEnumerable<T> list, Action<T> action)
|
||||||
{
|
{
|
||||||
MapperContext<T> result = new MapperContext<T>();
|
this.Context.Utilities.PageEach(list, 200, pageList =>
|
||||||
result.context = this.Context;
|
|
||||||
if (result.context.TempItems == null)
|
|
||||||
{
|
{
|
||||||
result.context.TempItems = new Dictionary<string, object>();
|
_ThenMapper(pageList, action);
|
||||||
}
|
});
|
||||||
var key = "Queryable_To_Context";
|
|
||||||
result.context.TempItems.Add(key, result);
|
|
||||||
result.list = list.ToList();
|
|
||||||
foreach (var item in list)
|
|
||||||
{
|
|
||||||
action.Invoke(item);
|
|
||||||
}
|
|
||||||
result.context.TempItems.Remove(key);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
public async Task ThenMapperAsync<T>(IEnumerable<T> list, Func<T, Task> action)
|
public async Task ThenMapperAsync<T>(IEnumerable<T> list, Func<T, Task> action)
|
||||||
{
|
{
|
||||||
MapperContext<T> result = new MapperContext<T>();
|
await this.Context.Utilities.PageEachAsync(list, 200,async pageList =>
|
||||||
result.context = this.Context;
|
|
||||||
if (result.context.TempItems == null)
|
|
||||||
{
|
{
|
||||||
result.context.TempItems = new Dictionary<string, object>();
|
await _ThenMapperAsync(pageList, action);
|
||||||
}
|
});
|
||||||
var key = "Queryable_To_Context";
|
|
||||||
result.context.TempItems.Add(key, result);
|
|
||||||
result.list = list.ToList();
|
|
||||||
foreach (var item in list)
|
|
||||||
{
|
|
||||||
await action.Invoke(item);
|
|
||||||
}
|
|
||||||
result.context.TempItems.Remove(key);
|
|
||||||
}
|
}
|
||||||
#endregion
|
#endregion
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user