mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-19 20:38:16 +08:00
- 优化 ToList<Dto> jsonb 映射;
This commit is contained in:
@ -218,6 +218,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
/// <returns></returns>
|
||||
public NativeTuple<List<T1>[], List<T1>[]> SplitSourceByIdentityValueIsNull(List<T1> source)
|
||||
{
|
||||
if (source.Any() == false) return NativeTuple.Create(new List<T1>[0], new List<T1>[0]);
|
||||
if (_SplitSourceByIdentityValueIsNullFlag == 1) return NativeTuple.Create(new[] { source }, new List<T1>[0]);
|
||||
if (_SplitSourceByIdentityValueIsNullFlag == 2) return NativeTuple.Create(new List<T1>[0], new[] { source });
|
||||
if (IdentityColumn == null) return NativeTuple.Create(LocalSplitSourceByAsTable(source), new List<T1>[0]);
|
||||
@ -234,6 +235,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
|
||||
List<T1>[] LocalSplitSourceByAsTable(List<T1> loc1)
|
||||
{
|
||||
if (loc1.Any() == false) return new List<T1>[0];
|
||||
if (_table.AsTableImpl != null)
|
||||
{
|
||||
var atarr = loc1.Select(a => new
|
||||
|
@ -255,12 +255,16 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
public List<TDto> ToList<TDto>() => ToList(GetToListDtoSelector<TDto>());
|
||||
public List<TDto> ToList<TDto>() => typeof(T1) == typeof(TDto) ? ToList() as List<TDto> : ToList(GetToListDtoSelector<TDto>());
|
||||
Expression<Func<T1, TDto>> GetToListDtoSelector<TDto>()
|
||||
{
|
||||
var expParam = _tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a");
|
||||
var expBinds = _tables[0].Table.Columns.Where(a => a.Value.CsType != a.Value.Attribute.MapType)
|
||||
.Select(a => Expression.Bind(typeof(TDto).GetProperty(a.Value.CsName), Expression.MakeMemberAccess(expParam, _tables[0].Table.Properties[a.Value.CsName])))
|
||||
.ToArray();
|
||||
return Expression.Lambda<Func<T1, TDto>>(
|
||||
typeof(TDto).InternalNewExpression(),
|
||||
_tables[0].Parameter ?? Expression.Parameter(typeof(T1), "a"));
|
||||
Expression.MemberInit(typeof(TDto).InternalNewExpression(), expBinds),
|
||||
expParam);
|
||||
}
|
||||
public void ToChunk<TReturn>(Expression<Func<T1, TReturn>> select, int size, Action<FetchCallbackArgs<List<TReturn>>> done)
|
||||
{
|
||||
@ -1284,7 +1288,7 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
return ret;
|
||||
}
|
||||
public Task<List<TDto>> ToListAsync<TDto>(CancellationToken cancellationToken = default) => ToListAsync(GetToListDtoSelector<TDto>(), cancellationToken);
|
||||
async public Task<List<TDto>> ToListAsync<TDto>(CancellationToken cancellationToken = default) => typeof(T1) == typeof(TDto) ? await ToListAsync(false, cancellationToken) as List<TDto> : await ToListAsync(GetToListDtoSelector<TDto>(), cancellationToken);
|
||||
|
||||
public Task<int> InsertIntoAsync<TTargetEntity>(string tableName, Expression<Func<T1, TTargetEntity>> select, CancellationToken cancellationToken = default) where TTargetEntity : class => base.InternalInsertIntoAsync<TTargetEntity>(tableName, select, cancellationToken);
|
||||
|
||||
|
Reference in New Issue
Block a user