mirror of
https://github.com/nsnail/FreeSql.git
synced 2025-06-18 20:08:15 +08:00
- 完善 $"{id}_{name}" lambda 解析与测试;
This commit is contained in:
@ -256,6 +256,20 @@ namespace FreeSql.Odbc.SqlServer
|
||||
return $"({arg2} is null or {arg2} = '' or ltrim({arg2}) = '')";
|
||||
case "Concat":
|
||||
return _common.StringConcat(exp.Arguments.Select(a => getExp(a)).ToArray(), exp.Arguments.Select(a => a.Type).ToArray());
|
||||
case "Format":
|
||||
if (exp.Arguments[0].NodeType != ExpressionType.Constant) throw new Exception($"未实现函数表达式 {exp} 解析,参数 {exp.Arguments[0]} 必须为常量");
|
||||
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 atype = (a as UnaryExpression)?.Operand.Type.NullableTypeOrThis() ?? a.Type.NullableTypeOrThis();
|
||||
if (atype == typeof(string)) return $"'+({ExpressionLambdaToSql(a, tsc)})+{nchar}'";
|
||||
if (atype == typeof(Guid)) return $"'+cast({ExpressionLambdaToSql(a, tsc)} as char(36))+{nchar}'";
|
||||
if (atype.IsNumberType()) return $"'+cast({ExpressionLambdaToSql(a, tsc)} as varchar)+{nchar}'";
|
||||
return $"'+cast({ExpressionLambdaToSql(a, tsc)} as nvarchar(max))+{nchar}'";
|
||||
}).ToArray();
|
||||
return string.Format(expArgs0, expArgs);
|
||||
}
|
||||
}
|
||||
else
|
||||
|
Reference in New Issue
Block a user