mirror of
https://gitee.com/dotnetchina/SqlSugar.git
synced 2025-08-23 22:11:36 +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;
|
||||
|
@ -168,41 +168,42 @@ namespace SqlSugar
|
||||
{
|
||||
var isSubSubQuery = this.allMethods.Select(it => it.ToString()).Any(it => Regex.Matches(it, "Subquery").Count > 1);
|
||||
var isubList = this.allMethods.Select(exp =>
|
||||
{
|
||||
if (isSubSubQuery)
|
||||
{
|
||||
this.context.JoinIndex = 1;
|
||||
this.context.SubQueryIndex = 0;
|
||||
}
|
||||
var methodName = exp.Method.Name;
|
||||
var items = SubTools.SubItems(this.context);
|
||||
var item = items.First(s => s.Name == methodName);
|
||||
if (item is SubWhere && hasWhere == false)
|
||||
{
|
||||
hasWhere = true;
|
||||
}
|
||||
else if (item is SubWhere)
|
||||
{
|
||||
item = items.First(s => s is SubAnd);
|
||||
}
|
||||
{
|
||||
if (isSubSubQuery)
|
||||
{
|
||||
this.context.JoinIndex = 1;
|
||||
this.context.SubQueryIndex = 0;
|
||||
}
|
||||
var methodName = exp.Method.Name;
|
||||
var items = SubTools.SubItems(this.context);
|
||||
var item = items.First(s => s.Name == methodName);
|
||||
if (item is SubWhere && hasWhere == false)
|
||||
{
|
||||
hasWhere = true;
|
||||
}
|
||||
else if (item is SubWhere)
|
||||
{
|
||||
item = items.First(s => s is SubAnd);
|
||||
}
|
||||
|
||||
if (item is SubWhereIF && hasWhere == false)
|
||||
{
|
||||
hasWhere = true;
|
||||
}
|
||||
else if (item is SubWhereIF)
|
||||
{
|
||||
item = items.First(s => s is SubAndIF);
|
||||
}
|
||||
else if (item is SubSelectStringJoin)
|
||||
{
|
||||
isXmlPath = true;
|
||||
}
|
||||
if (item is SubWhereIF && hasWhere == false)
|
||||
{
|
||||
hasWhere = true;
|
||||
}
|
||||
else if (item is SubWhereIF)
|
||||
{
|
||||
item = items.First(s => s is SubAndIF);
|
||||
}
|
||||
else if (item is SubSelectStringJoin)
|
||||
{
|
||||
isXmlPath = true;
|
||||
}
|
||||
|
||||
item.Context = this.context;
|
||||
item.Expression = exp;
|
||||
return item;
|
||||
}).ToList();
|
||||
item.Context = this.context;
|
||||
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