score:2

Accepted answer

If the Reviews property contains all Reviews for a particular Book this is simple:

var result = books.Select(book => new
{
    book.Title,
    Rating = book.Reviews.Average(review => review.Rating)
});

But if you have separate collections you will need to perform a join:

var result = books.GroupJoin(reviews, // One-to-many        
    book => book.Id,                  // Primary key
    review => review.Book.Id,         // Foreign key
    (book, reviews) => new            // Selection
    {
        book.Title,
        Rating = reviews.Average(review => review.Rating)
    });

Related Articles