You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
50 lines
2.0 KiB
50 lines
2.0 KiB
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Linq.Expressions;
|
|
|
|
namespace SqlSugar
|
|
{
|
|
|
|
public class CaseWhenResolve
|
|
{
|
|
List<MethodCallExpression> allMethods = new List<MethodCallExpression>();
|
|
private ExpressionContext context = null;
|
|
public CaseWhenResolve(MethodCallExpression expression, ExpressionContext context, Expression oppsiteExpression)
|
|
{
|
|
this.context = context;
|
|
var currentExpression = expression;
|
|
allMethods.Add(currentExpression);
|
|
if (context.IsSingle && oppsiteExpression != null&& oppsiteExpression is MemberExpression)
|
|
{
|
|
var childExpression = (oppsiteExpression as MemberExpression).Expression;
|
|
this.context.SingleTableNameSubqueryShortName = (childExpression as ParameterExpression).Name;
|
|
}
|
|
else if (context.IsSingle)
|
|
{
|
|
this.context.SingleTableNameSubqueryShortName = (context.Expression as LambdaExpression).Parameters.First().Name;
|
|
}
|
|
while (currentExpression != null)
|
|
{
|
|
var addItem = currentExpression.Object as MethodCallExpression;
|
|
if (addItem != null)
|
|
allMethods.Add(addItem);
|
|
currentExpression = addItem;
|
|
}
|
|
}
|
|
|
|
public string GetSql()
|
|
{
|
|
allMethods.Reverse();
|
|
var sqls = new List<KeyValuePair<string, string>>();
|
|
foreach (var methodExp in allMethods)
|
|
{
|
|
var isFirst = allMethods.First() == methodExp;
|
|
var isLast= allMethods.Last() == methodExp;
|
|
var sql= SubTools.GetMethodValue(this.context, methodExp.Arguments[0],this.context.IsSingle?ResolveExpressType.WhereSingle:ResolveExpressType.WhereMultiple);
|
|
sqls.Add(new KeyValuePair<string, string>(methodExp.Method.Name, sql));
|
|
}
|
|
var result= this.context.DbMehtods.CaseWhen(sqls);
|
|
return result;
|
|
}
|
|
}
|
|
}
|