Filtering whole of hierarchical list with LINQ?

I'm not sure of your exact needs with the filtered collection. I'm looking at it as a View-Model And a recursive extension method provides you with a neat way to achieve this filter: public static class Helper { public static ICollection EnabledWithChildren(this ICollection source) { var result = new List(); foreach (var ele in source) { if(ele. IsEnabled == true) { var productGroup = new ProductGroup{Id = ele.Id, IsEnabled = ele.

IsEnabled, ParentId = ele. ParentId}; if(ele. Children!

= null && ele.Children.Count() > 0) productGroup. Children = ele.Children. EnabledWithChildren(); result.

Add(productGroup); } } return result; } } And usage: public class ProductGroup { public int Id; public int? ParentId; public ICollection Children; public bool IsEnabled; static void Main() { var filteredProductGroups = ProductsGroups. EnabledWithChildren(); } }.

I'm not sure of your exact needs with the filtered collection. I'm looking at it as a View-Model. And a recursive extension method provides you with a neat way to achieve this filter: public static class Helper { public static ICollection EnabledWithChildren(this ICollection source) { var result = new List(); foreach (var ele in source) { if(ele.

IsEnabled == true) { var productGroup = new ProductGroup{Id = ele. Id, IsEnabled = ele. IsEnabled, ParentId = ele.

ParentId}; if(ele. Children! = null && ele.Children.Count() > 0) productGroup.

Children = ele.Children. EnabledWithChildren(); result. Add(productGroup); } } return result; } } And usage: public class ProductGroup { public int Id; public int?

ParentId; public ICollection Children; public bool IsEnabled; static void Main() { var filteredProductGroups = ProductsGroups. EnabledWithChildren(); } }.

The problem is that all of the productgroups will be loaded in memory before filtering. I would like to get EF to do the filtering using some clever LINQ if possible, i.e. Against the IQueryable so that only the needed records are returned from the database.My dataset could potentially have millions of records so it is important that I can get EF to filter out records correctly.

– Silverfox Oct 12 at 7:41.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions