c# - Looping through Model Collection and filter a query in asp.net mvc -
i have model in web-application this:
class myclass { int id; list<anotherclass> foo {get; set;} } class anotherclass { int id; string bar; }
i have list of filter-strings given user.
list<string> filter = new list<string> { "foo", "bar" } //as example
what want filter myclass
given strings this:
var result = context.myclass.include(mc => mc.foo); result = result.where(x => filter.any(f => f == x.foo.select(d => d.bar)));
the problem is: select()
returns list of strings , can't compare string list of strings.
anyone idea how fix issue?
if putting words want is: find whichever item in result, if of inner class items present in filter list
try:
result.where(item => item.any(inneritem => filter.contains(inneritem.bar)))
or in other syntax:
var output = (from item in result inneritem in item.foo filter.contains(inneritem.bar) select item);
Comments
Post a Comment