LINQ方法和使用OrderBy(),Take()和ToList()的顺序 [英] LINQ method and the order to use OrderBy() , Take() , and ToList()

查看:194
本文介绍了LINQ方法和使用OrderBy(),Take()和ToList()的顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我只是意识到我的LINQ方法并没有按照我的想象做任何事情.

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();

上面的查询未获得评分最高的5本图书,而是5本看似随机的图书.

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.

推荐答案

您的查询顺序正确; ReviewRating是什么类型?

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

这篇关于LINQ方法和使用OrderBy(),Take()和ToList()的顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆