开发者

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

开发者 https://www.devze.com 2023-01-24 20:49 出处:网络
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();

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?

0

精彩评论

暂无评论...
验证码 换一张
取 消