c# - Filtering a list in a list using linq -
i have list want filter based on user input.
so i've got this:
var fulllist = blogic.getdatastorecompaniesforfilterlist(); var filterlist = fulllist .where(w => w.name.tolower().startswith(filterstring.tolower()) || filterstring.length > 2 && w.vat.tolower().contains(filterstring.tolower()) || w.industrylang != null && w.industrylang.where(ww => ww.languageid == usrx.languageid) .select(s => s.name.tolower()) .contains(filterstring.tolower()) ).tolist();
more last part of filter query what's giving me troubles:
w.industrylang != null && w.industrylang.where(ww => ww.languageid == usrx.languageid) .select(s => s.name.tolower()).contains(filterstring.tolower())
the full list list of objects contains id, name, vat , possible list (hence null check) of industrylang objects. such industrylang object contains id, languageid check language , name.
what need able filter on name of industrylanguage.
it small mistake don't seem find it. appreciated! thanks.
if want entries in fulllist @ least 1 industrylang has name contains filtering condition, replace 'where' clause 'any' , include condition on industrylang object so:
var fulllist = blogic.getdatastorecompaniesforfilterlist(); var filterlist = fulllist .where(w => w.name.tolower().startswith(filterstring.tolower()) || filterstring.length > 2 && w.vat.tolower().contains(filterstring.tolower()) || w.industrylang != null && w.industrylang.any(ww => ww.languageid == usrx.languageid && ww.name.tolower().contains(filterstring.tolower())) ).tolist();
Comments
Post a Comment