Update exp to sql

This commit is contained in:
sunkaixuan
2022-05-15 11:43:02 +08:00
parent 1fd7305527
commit b8439a5bd3

View File

@@ -515,6 +515,11 @@ namespace SqlSugar
}); });
parameter.Context.Result.Append(this.Context.GetAsString(asName, sql)); parameter.Context.Result.Append(this.Context.GetAsString(asName, sql));
} }
else if (item.NodeType == ExpressionType.Not && (item as UnaryExpression).Operand is MethodCallExpression)
{
var asValue = packIfElse(GetNewExpressionValue(item)).ObjToString();
parameter.Context.Result.Append(this.Context.GetAsString(asName, asValue));
}
else if (item is MethodCallExpression || item is UnaryExpression || item is ConditionalExpression || item.NodeType == ExpressionType.Coalesce) else if (item is MethodCallExpression || item is UnaryExpression || item is ConditionalExpression || item.NodeType == ExpressionType.Coalesce)
{ {
this.Expression = item; this.Expression = item;
@@ -526,7 +531,15 @@ namespace SqlSugar
Check.ThrowNotSupportedException(item.GetType().Name); Check.ThrowNotSupportedException(item.GetType().Name);
} }
} }
public object packIfElse(object methodValue)
{
methodValue = this.Context.DbMehtods.CaseWhen(new List<KeyValuePair<string, string>>() {
new KeyValuePair<string, string>("IF",methodValue.ObjToString()),
new KeyValuePair<string, string>("Return","1"),
new KeyValuePair<string, string>("End","0")
});
return methodValue;
}
private static bool IsNotCaseExpression(Expression item) private static bool IsNotCaseExpression(Expression item)
{ {
if ((item as MethodCallExpression).Method.Name == "IIF") if ((item as MethodCallExpression).Method.Name == "IIF")