c# - Dynamic Linq select first in groups after GroupBy -


i think i've read every post on subject still can't seem work. want duplicate following groupby dynamic linq. i've tried dynamic groupby can't seem first().

var result = mydata     .groupby(g => g.id)     .select(z => z.first())     .select("new (id, field1, field2)"); 

the groupby needs dynamic. need first row of grouped field. so..

id:1, field1:w, field2:l  id:1, field1:a, field2:b  id:2, field1:a, field2:b  id:2, field1:c, field2:d  

should end being:

id:1, field1:w, field2:l  id:2, field1:a, field2:b  or id:1, field1:a, field2:b  id:2, field1:c, field2:d  

i solved adding dynamicqueryable

public static object first(this iqueryable source)         {             if (source == null) throw new argumentnullexception("source");             return source.provider.execute(                 expression.call(                     typeof(queryable), "first",                     new type[] { source.elementtype },                     source.expression));         } 

above not required..but added anyway consistency.

and adding ienumerablesignatures

void first() 

query becomes:

var result = mydata     .groupby("id", "it")     .select("it.first()")     .select("new (id, field1, field2)"); 

Comments

Popular posts from this blog

Java 3D LWJGL collision -

spring - SubProtocolWebSocketHandler - No handlers -

methods - python can't use function in submodule -