我想在常规的LINQ to串接在动态LINQ,即水木清华串像string.Join(",", g.Select(i => i.item1))
如何做好集团的毗连在System.Linq.Dynamic
我的动态LINQ看起来像这样
result.AsEnumerable().AsQueryable().GroupBy("new {it.id.ToString() as entity_id, it[\"item2\"] as item2}", "it").Select("new{key.entity_id, key.item2,
String.Join(\", \", it.Select(it[\"item1\"].ToString())) as item1}")
但这显然是不行的,任何想法 我只想要一个逗号分隔字符串,每个组的
数据的编辑新增的例子:
只是为了举例说明数据的问题 它的样子:
注:项目1的PK 1重复两次,因为它来自一个N:N的关系,我需要集团的毗连它说PK
议决
我已经找到一种方法来解决这个问题,在我的情况,我需要通过pil0t 更多的功能添加到System.Linq.Dynamic,按照How to implement SelectMany in System.Linq.Dynamic ExpressionParser按您需要更改
1回答)签名接口IEnumerableSignatures 并添加到它:
void Select(string selector); void SelectMany(string selector);/*not needed for this but good to have*/
2)修改ParseAggregate功能按照他/她的答案补充
.... if (signature.Name == "Min" || signature.Name == "Max") { typeArgs = new Type[] { elementType, args[0].Type }; } else if (signature.Name == "Select") { typeArgs = new Type[] { elementType, Expression.Lambda(args[0],innerIt).Body.Type}; } else if (signature.Name == "SelectMany") { var type = Expression.Lambda(args[0], innerIt).Body.Type; var interfaces = type.GetInterfaces().Union(new[] { type }); Type resultType = interfaces.Single(a => a.Name == typeof(IEnumerable<>).Name).GetGenericArguments()[0]; typeArgs = new Type[] { elementType, resultType }; } ....
3)重新编译添加到项目
4)使用方法如下:的string.join(\ “\”,选择(它[\ “物品1 \”]的ToString())
谢谢你的回应,但即时搜索**组连接**,我添加了上面的数据的例子 – OOIOIOO