开发者

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?

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜