- 增加 SqlServer lambda 表达式树解析子查询 ToList + string.Join() 产生 类似 group_concat 的效果;#405

This commit is contained in:
28810
2020-08-08 00:53:27 +08:00
parent 25e73117b1
commit 1a8c7ce86d
4 changed files with 68 additions and 0 deletions

View File

@ -283,6 +283,24 @@ namespace FreeSql.SqlServer
return $"'+{_common.IsNull($"cast({ExpressionLambdaToSql(a, tsc)} as nvarchar(max))", "''")}+{nchar}'";
}).ToArray();
return string.Format(expArgs0, expArgs);
case "Join":
if (exp.IsStringJoin(out var joinExpArgs1, out var joinExpArgs1Args0))
{
var newToListArgs0 = Expression.Call(joinExpArgs1.Object, joinExpArgs1.Method,
Expression.Lambda(
Expression.Call(
typeof(string).GetMethod("Concat", new[] { typeof(object), typeof(object) }),
Expression.Convert(joinExpArgs1Args0.Body, typeof(object)),
Expression.Convert(exp.Arguments[0], typeof(object))),
joinExpArgs1Args0.Parameters));
var newToListSql = getExp(newToListArgs0);
if (string.IsNullOrEmpty(newToListSql) == false && newToListSql.StartsWith("(") && newToListSql.EndsWith(")"))
{
newToListSql = $"{newToListSql.Substring(0, newToListSql.Length - 1)} FOR XML PATH(''))";
return newToListSql;
}
}
break;
}
}
else