哪个更好,更快IQueryable或列表 [英] Which is better and fast IQueryable or List

查看:103
本文介绍了哪个更好,更快IQueryable或列表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

哪个更好更快IQueryable或List

解决方案

你问的是两个完全不同的结构。列表<>是一个强大的集合,支持插入以及一些其他实用功能,使其比[]更强大。有关可枚举类型的优秀入门:

List vs IEnumerable vs IQueryable vs ICollection vs IDictionary [ ^ ]



IQueryable设计为Lazy<>包装器,它将为过滤的IEnumerable提供一个钩子,而不是IEnuerable本身。这对于高开销情况(大型lsists,慢速数据访问等)非常有用,其中不需要预先加载所有数据并且会对应用程序性能产生负面影响。 IQueryable在实体框架中广泛使用,因为它表示驻留在SQL数据库中的数据,并且您可以在调用实际拉取数据之前执行多个筛选和排序操作。 IQueryable不是IEnumerable(真的),直到调用GetEnumerator,此时它将下拉它作为代理的数据。



简而言之:除非您正在处理旨在使用IQuerable的库,否则请使用List来处理您将要操作的集合,并使用[]作为需要读取的项目列表。

Which is better and fast IQueryable or List

解决方案

You're asking about two structures that do completely different things. A List<> is a robust collection that supports inserts as well as a few other utility functions that make it more robust than []. There is an excellent primer on enumerable types at:
List vs IEnumerable vs IQueryable vs ICollection vs IDictionary[^]

IQueryable is designed to be a Lazy<> wrapper that will provide a hook to a filtered IEnumerable, not the IEnuerable itself. This is useful for high-overhead situations (large lsists, slow data access, etc) where loading ALL data upfront is un-needed and will negatively impact application perfomance. IQueryable is used extensively in the entity Framework because it represents data that resides on a SQL database, and you may perform several filtering and sorting operations before a call is made to actually pull the data down. An IQueryable is not an IEnumerable(really) until GetEnumerator is called on it, at which point it will pull down that data that it is acting as a proxy for.

To be concise in an answer though: Unless you are dealing with a library that is designed to use IQuerable, use a List for a collection that you will be manipulating, and use [] for a list of items that just need to be read.


这篇关于哪个更好,更快IQueryable或列表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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