OrderBy()。ToLisT()和ToList()之间有什么区别.QuickBy()? [英] What is difference between OrderBy().ToLisT() and ToList().OrderBy() ?

查看:97
本文介绍了OrderBy()。ToLisT()和ToList()之间有什么区别.QuickBy()?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我在接受采访时问了一个问题,即OrderBy()。ToLisT()和ToList()之间有什么区别.QuickBy()?我回答说使用第一个是性能开销,因为ToList强制要评估所有内容。但他并不同意我的论点,并要求我全面解释。能帮助我深入了解这些吗?



提前谢谢

Hi,

I happened to asked a question in interview that what is difference between OrderBy().ToLisT() and ToList().OrderBy()? I replied there is performance overhead using first one as ToList forces everything to be evaluated. But he didn't' agree with my argument and asked me to explain comprehensively. Can you please help me to understand these in depth ?

Thanks in advance

推荐答案

你对表演的看法是对的(至少在全球范围内) )...

OrderBy()。ToList()版本应该表现更好的原因是LINQ to Entities会将OrderBy()转换为SQL ORDER BY语句,其性能比任何语句都要好得多排序方法......

并不总是如此,因为订单的表达式可能过于复杂而无法将其传递给SQL,在这种情况下,LINQ to Entities会首先评估数据......
You were right about the performance thing (at the global level at least)...
The reason that the OrderBy().ToList() version should perform better is that LINQ to Entities will translate that OrderBy() to an SQL ORDER BY statement that perform much better than any sorting method...
It is not always true as the expression for order may be too complex to pass it to SQL in which case LINQ to Entities will evaluate data first anyway...


这篇关于OrderBy()。ToLisT()和ToList()之间有什么区别.QuickBy()?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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