asfsadf
asfsadf

Reputation: 3862

LINQ method and the order to use OrderBy() , Take() , and ToList()

I just realized that my LINQ methods aren't doing anything at all what I thought they were.

HighestRatedBooks = allBooks.OrderByDescending(b => b.Review.Rating).Take(5).ToList();

The above query doesn't get the top 5 highest rated books, but rather 5 seemingly random books.

What would the correct query look like?

Right now this is returning books that don't even have a rating, much less a high one.

Upvotes: 0

Views: 2069

Answers (1)

Andrew Barber
Andrew Barber

Reputation: 40150

Your query is ordered correctly; what are the Review and Rating types?

Upvotes: 2

Related Questions