diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs index 5609acb2c..c8b806cd4 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/Common/ExpressionTool.cs @@ -130,6 +130,14 @@ namespace SqlSugar return newExp; } + public static string GetMethodName(Expression expression) + { + if (expression is MethodCallExpression) + { + return (expression as MethodCallExpression).Method.Name; + } + return null; + } public static Type GetMemberInfoType(MemberInfo member) { diff --git a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs index a0a425270..a5638d9da 100644 --- a/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs +++ b/Src/Asp.Net/SqlSugar/ExpressionsToSql/ResolveItems/BaseResolve.cs @@ -530,6 +530,11 @@ namespace SqlSugar } } } + else if (IsExtSqlFuncObj(item)) + { + var value = GetNewExpressionValue(item); + parameter.Context.Result.Append($" {value} AS {asName} "); + } else { asName = GetAsNameResolveAnObject(parameter, item, asName, isSameType); @@ -744,6 +749,11 @@ namespace SqlSugar #endregion #region Validate + + private bool IsExtSqlFuncObj(Expression item) + { + return this.Context.SqlFuncServices != null && item is MethodCallExpression && this.Context.SqlFuncServices.Any(it => it.UniqueMethodName == ExpressionTool.GetMethodName(item)); + } private bool IsNullValue(ExpressionParameter parameter, object value) { return value == null