- 修复 $"{a.Code}_{a.Id}" lambda 解析当 {} 多于3个时的 bug(.net 内部机制很坑);

> 3个 {} 时,Arguments[1..3] 解析出来是分开的
> 4个 {} 时,Arguments[1] 只能解析这个出来,然后 [1] 里面是 NewArray []
This commit is contained in:
28810
2020-07-29 10:59:47 +08:00
parent c2749bad65
commit de86beba4f
30 changed files with 445 additions and 30 deletions

View File

@ -261,7 +261,11 @@ namespace FreeSql.Odbc.SqlServer
var expArgs0 = ExpressionLambdaToSql(exp.Arguments[0], tsc);
if (exp.Arguments.Count == 1) return expArgs0;
var nchar = expArgs0.StartsWith("N'") ? "N" : "";
var expArgs = exp.Arguments.Where((a, z) => z > 0).Select(a =>
var expArgsHack = exp.Arguments.Count == 2 && exp.Arguments[1].NodeType == ExpressionType.NewArrayInit ?
(exp.Arguments[1] as NewArrayExpression).Expressions : exp.Arguments.Where((a, z) => z > 0);
//3个 {} 时Arguments 解析出来是分开的
//4个 {} 时Arguments[1] 只能解析这个出来,然后里面是 NewArray []
var expArgs = expArgsHack.Select(a =>
{
var atype = (a as UnaryExpression)?.Operand.Type.NullableTypeOrThis() ?? a.Type.NullableTypeOrThis();
if (atype == typeof(string)) return $"'+{_common.IsNull(ExpressionLambdaToSql(a, tsc), "''")}+{nchar}'";