Answer the question
In order to leave comments, you need to log in
How to select data correctly with LINQ?
Hello. There is a structure like this:
class Book
{
public string Name { get; set; }
public string Author { get; set; }
}
class User
{
public string Name { get; set; }
public int Age { get; set; }
public Book[] Books;
}
var us = Users.SelectMany(u => u.Books)
.Where(b => b.Author == "Достоевский")
.Distinct()
.Select(b => b.Name);
Answer the question
In order to leave comments, you need to log in
Users
.Where(u => u.Books
.Any(b => b.Author == "Достоевский"))
.Select(u => u.Name)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question