mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-09-24 04:53:45 +08:00
Update Orderby
This commit is contained in:
@@ -139,6 +139,11 @@ namespace OrmTest
|
||||
};
|
||||
var five=db.Ado.ExecuteCommand("11111");
|
||||
db.CurrentConnectionConfig.SqlMiddle = null;
|
||||
db.GetConnectionWithAttr<Order>().Queryable<Order>().ToList();
|
||||
var test34 = db.Queryable<Order>().OrderBy(it=>new {
|
||||
id= it.Id,
|
||||
name=SqlFunc.Asc(it.Name),
|
||||
}).ToList();
|
||||
Console.WriteLine("#### Examples End ####");
|
||||
}
|
||||
|
||||
|
@@ -1911,7 +1911,28 @@ namespace SqlSugar
|
||||
{
|
||||
QueryBuilder.CheckExpression(expression, "OrderBy");
|
||||
var isSingle = QueryBuilder.IsSingle();
|
||||
if ((expression as LambdaExpression).Body is NewExpression)
|
||||
if (expression.ToString().IsContainsIn("Desc(", "Asc("))
|
||||
{
|
||||
var orderValue = "";
|
||||
var newExp = (expression as LambdaExpression).Body as NewExpression;
|
||||
foreach (var item in newExp.Arguments)
|
||||
{
|
||||
if (item is MemberExpression)
|
||||
{
|
||||
orderValue +=
|
||||
QueryBuilder.GetExpressionValue(item, isSingle ? ResolveExpressType.FieldSingle : ResolveExpressType.FieldMultiple).GetResultString() + ",";
|
||||
}
|
||||
else
|
||||
{
|
||||
orderValue +=
|
||||
QueryBuilder.GetExpressionValue(item, isSingle ? ResolveExpressType.WhereSingle : ResolveExpressType.WhereMultiple).GetResultString() + ",";
|
||||
}
|
||||
}
|
||||
orderValue = orderValue.TrimEnd(',');
|
||||
OrderBy(orderValue);
|
||||
return this;
|
||||
}
|
||||
else if ((expression as LambdaExpression).Body is NewExpression)
|
||||
{
|
||||
var lamResult = QueryBuilder.GetExpressionValue(expression, isSingle ? ResolveExpressType.ArraySingle : ResolveExpressType.ArrayMultiple);
|
||||
var items = lamResult.GetResultString().Split(',').Where(it => it.HasValue()).Select(it => it + UtilConstants.Space + type.ToString().ToUpper()).ToList();
|
||||
|
@@ -526,5 +526,14 @@ namespace SqlSugar
|
||||
var parameter2 = model.Args[1];
|
||||
return string.Format(" ({0} <= {1}) ", parameter.MemberName, parameter2.MemberName);
|
||||
}
|
||||
|
||||
public virtual string Asc(MethodCallExpressionModel model)
|
||||
{
|
||||
return model.Args[0].MemberName + " ASC ";
|
||||
}
|
||||
public virtual string Desc(MethodCallExpressionModel model)
|
||||
{
|
||||
return model.Args[0].MemberName + " DESC ";
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@@ -81,5 +81,7 @@ namespace SqlSugar
|
||||
string GreaterThanOrEqual(MethodCallExpressionModel model);
|
||||
string LessThan(MethodCallExpressionModel model);
|
||||
string LessThanOrEqual(MethodCallExpressionModel model);
|
||||
string Asc(MethodCallExpressionModel model);
|
||||
string Desc(MethodCallExpressionModel model);
|
||||
}
|
||||
}
|
||||
|
@@ -9,7 +9,14 @@ namespace SqlSugar
|
||||
{
|
||||
public partial class SqlFunc
|
||||
{
|
||||
|
||||
public static T Desc<T>(T value)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
public static T Asc<T>(T value)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
}
|
||||
public static int DateDiff(DateType dateType,DateTime littleTime, DateTime bigTime)
|
||||
{
|
||||
throw new NotSupportedException("Can only be used in expressions");
|
||||
|
@@ -910,6 +910,10 @@ namespace SqlSugar
|
||||
return this.Context.DbMehtods.LessThan(model);
|
||||
case "LessThanOrEqual":
|
||||
return this.Context.DbMehtods.LessThanOrEqual(model);
|
||||
case "Asc":
|
||||
return this.Context.DbMehtods.Asc(model);
|
||||
case "Desc":
|
||||
return this.Context.DbMehtods.Desc(model);
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
Reference in New Issue
Block a user