tags:

views:

50

answers:

1

I have 3 classes in C#:

class Folder
{
    int Id { get; set; }
    List<File> files { get; set;}
}

class File
{
    int Id { get; set; }
    Author author { get; set; }
}

class Author
{
    int Id { get; set; }
    string Name { get; set; }
} 

I have a list of Folder items (List):

var folders = getAllFolders();

How can I use Linq to return a list of Folders from the list when i only know the Author id of the files?

I need the list to contain all folders where a given Author has created a file!

Thanks

+4  A: 

You want to find the folders where Any of the files have the Author id equal to the one you are looking for.

var authFolders = folders.Where( fo => fo.files.Any( fi => fi.Author.Id == authorId ));
tvanfosson
Probably too many f's, but this is the idea.
Kobi
@Kobi -- yep. I keep saying that SO needs intellisense, but they keep ignoring me. :-)
tvanfosson