mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-20 04:48:16 +08:00
- 优化 兼容排序 OrderBy(a => new {}) 语法;
This commit is contained in:
@ -760,8 +760,32 @@ namespace FreeSql.Internal.CommonProvider
|
||||
_commonExpression.ExpressionJoinLambda(_tables, joinType, exp, null, _whereGlobalFilter);
|
||||
return this as TSelect;
|
||||
}
|
||||
protected TSelect InternalOrderBy(Expression column) => this.OrderBy(_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, column, true, null));
|
||||
protected TSelect InternalOrderByDescending(Expression column) => this.OrderBy($"{_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, column, true, null)} DESC");
|
||||
protected TSelect InternalOrderBy(Expression column)
|
||||
{
|
||||
if (column.NodeType == ExpressionType.Lambda) column = (column as LambdaExpression)?.Body;
|
||||
switch (column?.NodeType)
|
||||
{
|
||||
case ExpressionType.New:
|
||||
var newExp = column as NewExpression;
|
||||
if (newExp == null) break;
|
||||
for (var a = 0; a < newExp.Members.Count; a++) this.OrderBy(_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, newExp.Arguments[a], true, null));
|
||||
return this as TSelect;
|
||||
}
|
||||
return this.OrderBy(_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, column, true, null));
|
||||
}
|
||||
protected TSelect InternalOrderByDescending(Expression column)
|
||||
{
|
||||
if (column.NodeType == ExpressionType.Lambda) column = (column as LambdaExpression)?.Body;
|
||||
switch (column?.NodeType)
|
||||
{
|
||||
case ExpressionType.New:
|
||||
var newExp = column as NewExpression;
|
||||
if (newExp == null) break;
|
||||
for (var a = 0; a < newExp.Members.Count; a++) this.OrderBy($"{_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, newExp.Arguments[a], true, null)} DESC");
|
||||
return this as TSelect;
|
||||
}
|
||||
return this.OrderBy($"{_commonExpression.ExpressionSelectColumn_MemberAccess(_tables, null, SelectTableInfoType.From, column, true, null)} DESC");
|
||||
}
|
||||
|
||||
public List<TReturn> InternalToList<TReturn>(Expression select) => this.ToListMapReader<TReturn>(this.GetExpressionField(select));
|
||||
protected string InternalToSql<TReturn>(Expression select, FieldAliasOptions fieldAlias = FieldAliasOptions.AsIndex)
|
||||
|
@ -96,6 +96,15 @@ namespace FreeSql.Internal.CommonProvider
|
||||
}
|
||||
public void InternalOrderBy(Expression exp, bool isDescending)
|
||||
{
|
||||
if (exp.NodeType == ExpressionType.Lambda) exp = (exp as LambdaExpression)?.Body;
|
||||
if (exp?.NodeType == ExpressionType.New)
|
||||
{
|
||||
var newExp = exp as NewExpression;
|
||||
if (newExp != null)
|
||||
for (var a = 0; a < newExp.Members.Count; a++)
|
||||
InternalOrderBy(newExp.Arguments[a], isDescending);
|
||||
return;
|
||||
}
|
||||
var sql = _comonExp.ExpressionWhereLambda(null, exp, this, null, null);
|
||||
var method = _select.GetType().GetMethod("OrderBy", new[] { typeof(string), typeof(object) });
|
||||
method.Invoke(_select, new object[] { isDescending ? $"{sql} DESC" : sql, null });
|
||||
|
Reference in New Issue
Block a user