c# - Linq Return Filtered Children -
I have a 'duh' moment where it seems that it should be straight forward, but I do not think so right understanding. I have a simple archive:
Category name --- & gt; & Lt; Category & gt; (Children of this category)
I want the user to be able to filter by category. During the name hierarchy retention. for example.
My class --- & gt; Category .name, "ABC" --- & gt; Category .name, "123" --- & gt; Category: Name, "CDE"
If User Type C, Filter should be returned
My Category --- & gt; Category .name, "ABC" --- & gt; Category name, "CDE"
My attempt is far off
var v = vm.CategoryList Where (P => gtcategoryItems any. (Q = & gt; q.Name.Contains (SearchText)));
It will filter and return all category names that include items that match the category, but I still have a list of full child category, which is unfilled What am I missing?
You need to call select
and return a filtered hair list, Like this:
var v = vm.CategoryList Select (P = & gt; new {p.CategoryName, CategoryItems = p.CategoryItems.Where (q = & gt; q.Name. (Search text))). Where (P => P category item. Any ()));
Comments
Post a Comment