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 =&开发者_开发问答gt; 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.
Your query is ordered correctly; what are the Review
and Rating
types?
精彩评论