mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-24 07:22:57 +08:00
Update exp to sql
This commit is contained in:
parent
e0f68485fb
commit
a2506a25c1
@ -8,6 +8,7 @@ namespace SqlSugar
|
||||
{
|
||||
public class SubOrderBy : ISubOperation
|
||||
{
|
||||
public int OrderIndex { get; set; } = 0;
|
||||
public bool HasWhere
|
||||
{
|
||||
get; set;
|
||||
@ -27,7 +28,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
return 480;
|
||||
return 480+OrderIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@ -44,7 +45,7 @@ namespace SqlSugar
|
||||
}
|
||||
var exp = expression as MethodCallExpression;
|
||||
var argExp = exp.Arguments[0];
|
||||
var result = "ORDER BY " + SubTools.GetMethodValue(this.Context, argExp, ResolveExpressType.FieldSingle);
|
||||
var result =(OrderIndex==0? "ORDER BY ":",") + SubTools.GetMethodValue(this.Context, argExp, ResolveExpressType.FieldSingle);
|
||||
var selfParameterName = this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
|
||||
result = result.Replace(selfParameterName, SubTools.GetSubReplace(this.Context));
|
||||
return result;
|
||||
@ -52,6 +53,7 @@ namespace SqlSugar
|
||||
}
|
||||
public class SubOrderByDesc : ISubOperation
|
||||
{
|
||||
public int OrderIndex { get; set; } = 0;
|
||||
public bool HasWhere
|
||||
{
|
||||
get; set;
|
||||
@ -71,7 +73,7 @@ namespace SqlSugar
|
||||
{
|
||||
get
|
||||
{
|
||||
return 480;
|
||||
return 480+OrderIndex;
|
||||
}
|
||||
}
|
||||
|
||||
@ -84,7 +86,7 @@ namespace SqlSugar
|
||||
{
|
||||
var exp = expression as MethodCallExpression;
|
||||
var argExp = exp.Arguments[0];
|
||||
var result = "ORDER BY " + SubTools.GetMethodValue(this.Context, argExp, ResolveExpressType.FieldSingle)+" DESC";
|
||||
var result = (OrderIndex == 0 ? "ORDER BY " : ",") + SubTools.GetMethodValue(this.Context, argExp, ResolveExpressType.FieldSingle)+" DESC";
|
||||
var selfParameterName = this.Context.GetTranslationColumnName((argExp as LambdaExpression).Parameters.First().Name) + UtilConstants.Dot;
|
||||
result = result.Replace(selfParameterName, string.Empty);
|
||||
return result;
|
||||
|
@ -203,6 +203,7 @@ namespace SqlSugar
|
||||
item.Expression = exp;
|
||||
return item;
|
||||
}).ToList();
|
||||
SetOrderByIndex(isubList);
|
||||
isubList.Insert(0, new SubBegin());
|
||||
if (isubList.Any(it => it is SubSelect))
|
||||
{
|
||||
@ -229,5 +230,28 @@ namespace SqlSugar
|
||||
this.context.JoinIndex = 0;
|
||||
return result;
|
||||
}
|
||||
|
||||
private static void SetOrderByIndex(List<ISubOperation> isubList)
|
||||
{
|
||||
var orderByIndex = 0;
|
||||
var orderByList = isubList.Where(it => it is SubOrderBy || it is SubOrderByDesc).ToList();
|
||||
if (orderByList.Count > 1)
|
||||
{
|
||||
orderByList.Reverse();
|
||||
foreach (var item in orderByList)
|
||||
{
|
||||
if (item is SubOrderBy)
|
||||
{
|
||||
(item as SubOrderBy).OrderIndex = orderByIndex;
|
||||
orderByIndex++;
|
||||
}
|
||||
else if (item is SubOrderByDesc)
|
||||
{
|
||||
(item as SubOrderByDesc).OrderIndex = orderByIndex;
|
||||
orderByIndex++;
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user