mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-04-22 18:52:50 +08:00
- 优化 ToAggregate 执行时忽略已设置的 OrderBy;
This commit is contained in:
parent
e777e7e86f
commit
e1a265f7aa
@ -710,6 +710,10 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
|
||||
protected TReturn InternalToAggregate<TReturn>(Expression select)
|
||||
{
|
||||
var tmpOrderBy = _orderby;
|
||||
_orderby = null; //解决 select count(1) from t order by id 这样的 SQL 错误
|
||||
try
|
||||
{
|
||||
var map = new ReadAnonymousTypeInfo();
|
||||
var field = new StringBuilder();
|
||||
@ -718,6 +722,11 @@ namespace FreeSql.Internal.CommonProvider
|
||||
_commonExpression.ReadAnonymousField(_tables, field, map, ref index, select, null, null, _whereCascadeExpression, null, false); //不走 DTO 映射,不处理 IncludeMany
|
||||
return this.ToListMapReader<TReturn>(new ReadAnonymousTypeAfInfo(map, field.Length > 0 ? field.Remove(0, 2).ToString() : null)).FirstOrDefault();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_orderby = tmpOrderBy;
|
||||
}
|
||||
}
|
||||
|
||||
public TSelect InternalWhere(Expression exp) => exp == null ? this as TSelect : this.Where(_commonExpression.ExpressionWhereLambda(_tables, exp, null, _whereCascadeExpression, _params));
|
||||
|
||||
@ -966,6 +975,10 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
|
||||
async protected Task<TReturn> InternalToAggregateAsync<TReturn>(Expression select)
|
||||
{
|
||||
var tmpOrderBy = _orderby;
|
||||
_orderby = null; //解决 select count(1) from t order by id 这样的 SQL 错误
|
||||
try
|
||||
{
|
||||
var map = new ReadAnonymousTypeInfo();
|
||||
var field = new StringBuilder();
|
||||
@ -974,6 +987,11 @@ namespace FreeSql.Internal.CommonProvider
|
||||
_commonExpression.ReadAnonymousField(_tables, field, map, ref index, select, null, null, _whereCascadeExpression, null, false); //不走 DTO 映射,不处理 IncludeMany
|
||||
return (await this.ToListMapReaderAsync<TReturn>(new ReadAnonymousTypeAfInfo(map, field.Length > 0 ? field.Remove(0, 2).ToString() : null))).FirstOrDefault();
|
||||
}
|
||||
finally
|
||||
{
|
||||
_orderby = tmpOrderBy;
|
||||
}
|
||||
}
|
||||
#endif
|
||||
#endregion
|
||||
}
|
||||
|
Loading…
x
Reference in New Issue
Block a user