c# - How to use GroupBy with ICollections? -


i use groupby grouping objects like:

var categories=     tovrdb.myobjects.asenumerable().where(t => myhashset.contains(t.id))                       .groupby(t => t.specialization, t => t,                                (key, g) => new {name = key.name, categoryitems = g.tolist()})                       .orderby(t => string.isnullorempty(t.name))                       .thenby(t => t.name)                       .tolist(); 

it's works fine.
want group objects specialization icollection<>.
example:

myobject1: "berlay's meat" specializations{chicken, pork, beef}  myobject2: "wonday's chickery" specializations{chicken}   myobject3: "rooki's meat" specializations{chicken, pork} 

and after group by:

pork{myobject1: "berlay's meat",myobject3: "rooki's meat"} beef{myobject1: "berlay's meat"} chicken{myobject1: "berlay's meat",myobject2: "wonday's chickery", myobject3: "rooki's meat"} 

any advises?

withcategories as:

var categories = tovrdb.myobjects.asenumerable().where(t => myhashset.contains(t.id));  var catsgrouped = categories.selectmany(     x => x.specializations, // specializations ienumerable<specialization>     (x, y) => new     {         category = x,         specialization = y,     }).groupby(x => x.specialization, x => x.category)     .toarray(); 

i used selectmany "multiply" each category specializations... regrouped result specialization. result igrouping<specialization, myobject>[]


Comments

Popular posts from this blog

c++ - Difference between pre and post decrement in recursive function argument -

php - Nothing but 'run(); ' when browsing to my local project, how do I fix this? -

php - How can I echo out this array? -