c# - Select property of an object that is in a list of objects which is also in another list of objects -


i have next arhitecture:

public class element {     public uint id { get; set; }     public icollection<elementdetails> elementdetails { get; set; } } public class elementdetails {     public string elementtitle { get; set; }     public string content { get; set; } } 

and there's list<element> somelist contains hundreds of elements. i'm trying obtain list of elementtitle (strings) contains text (i've called "seed"). want accomplish it's typeahead. here attempt:

list<element> suggestedelements = somelist.where(s => s.elementdetails.any(ss => ss.elementtitle.contains(seed))).tolist(); list<string> suggestions = suggestedelements .selectmany(t => t.elementdetails.select(x => x.elementtitle)).tolist() }); // contains elementtitle, including elementtitle don't contain "seed"... 

how can rid of elements don't contain seed?

list<string> suggestions = somelist.selectmany(x => x.elementdetails)                                    .where(y => y.elementtitle.contains(seed))                                    .select(z => z.elementtitle)                                    .tolist(); 

even simpler:

list<string> suggestions  = somelist.selectmany(x => x.elementdetails)                                     .select(y => y.elementtitle);                                     .where(z => z.contains(seed))                                     .tolist(); 

Comments

Popular posts from this blog

linux - xterm copying to CLIPBOARD using copy-selection causes automatic updating of CLIPBOARD upon mouse selection -

qt - Errors in generated MOC files for QT5 from cmake -