- 优化 表达式中不能使用 c# 函数的问题,

> 如:where(a => HttpContext.Session.GetString("UserID") == a.UserId)
This commit is contained in:
28810
2019-07-29 10:27:39 +08:00
parent 4609c910dd
commit 256963907e
3 changed files with 27 additions and 2 deletions

View File

@ -837,6 +837,7 @@ namespace FreeSql.Internal
//}
var other3Exp = ExpressionLambdaToSqlOther(exp3, tsc);
if (string.IsNullOrEmpty(other3Exp) == false) return other3Exp;
if (exp3.IsParameter() == false) return formatSql(Expression.Lambda(exp3).Compile().DynamicInvoke(), tsc.mapType);
throw new Exception($"未实现函数表达式 {exp3} 解析");
case ExpressionType.Parameter:
case ExpressionType.MemberAccess:
@ -1097,7 +1098,11 @@ namespace FreeSql.Internal
case ExpressionType.Coalesce:
return _common.IsNull(ExpressionLambdaToSql(expBinary.Left, tsc), ExpressionLambdaToSql(expBinary.Right, tsc));
}
if (dicExpressionOperator.TryGetValue(expBinary.NodeType, out var tryoper) == false) return "";
if (dicExpressionOperator.TryGetValue(expBinary.NodeType, out var tryoper) == false)
{
if (exp.IsParameter() == false) return formatSql(Expression.Lambda(exp).Compile().DynamicInvoke(), tsc.mapType);
return "";
}
return ExpressionBinary(tryoper, expBinary.Left, expBinary.Right, tsc);
}