c# - Linq group by select -


i have following linq expression , need add 2 extrastring fields (newfieldwhat , newfieldby) record-object in result-list. string-value either first or last, no difference. how can achieve that?

list<record> groupedtable = (from t in recordtable                     group t new {t.groupby1}                     grp                         select new                         record{                             groupby1 = grp.key.groupby1,                             attribute1 = grp.sum(t => t.attribute1),                             newfieldwhat = ?                             newfieldby = ?                         }).orderby(a => a.groupby1).tolist(); 

this comment makes clearer:

newfieldwhat = grp.first(t => t.newfieldwhat)  

gives me: "cannot convert 'string' 'bool'. newfieldwhat string"

i think want:

newfieldwhat = grp.first().newfieldwhat 

or, if want of group:

newfieldwhat = string.join(",", grp.select(t => t.newfieldwhat)) 

Popular posts from this blog

c# - ODP.NET Oracle.ManagedDataAccess causes ORA-12537 network session end of file -

matlab - Compression and Decompression of ECG Signal using HUFFMAN ALGORITHM -

utf 8 - split utf-8 string into bytes in python -