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

1 Answer 1

4

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 ));
Sign up to request clarification or add additional context in comments.

1 Comment

@Kobi -- yep. I keep saying that SO needs intellisense, but they keep ignoring me. :-)

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.