I need to filter a hierarchical list like:
- Folder 1
- Folder 2
- Document 1
- Document 2
- Folder 4
- Document 3
- Document 4
- Folder 3
- Document
Each folder has folders and/or documents. Each document has a Status enum.
How can i get all empty Folders or with documents where the status from the document is on “Deleted”?
var folders = from f in context.Folders
// where f.Documents.All( d => d.Status == DocumentStatus.Deleted )
select f;
Lazy loading is enabled.
How about this:
Unfortunately you have a more complex structure, the above linq statement will work only of folders have documents and not other folders.
To do what you want to do you will have to define a Predicate manually and filter with that, because in the case that a folder has children which are folders themselves, you have to recursively call the filter method to see if the condition is true.