IEnumerable<T>和IQuryable<T>的区别
https://stackoverflow.com/questions/1578778/using-iqueryable-with-linq/1578809#1578809
The main difference, from a user's perspective, is that, when you use IQueryable<T>
(with a provider that supports things correctly), you can save a lot of resources.
For example, if you're working against a remote database, with many ORM systems, you have the option of fetching data from a table in two ways, one which returns IEnumerable<T>
, and one which returns an IQueryable<T>
. Say, for example, you have a Products table, and you want to get all of the products whose cost is >$25.
If you do:
IEnumerable<Product> products = myORM.GetProducts();
var productsOver25 = products.Where(p => p.Cost >= 25.00);
What happens here, is the database loads all of the products, and passes them across the wire to your program. Your program then filters the data. In essence, the database does a SELECT * FROM Products
, and returns EVERY product to you.
With the right IQueryable<T>
provider, on the other hand, you can do:
IQueryable<Product> products = myORM.GetQueryableProducts();
var productsOver25 = products.Where(p => p.Cost >= 25.00);
The code looks the same, but the difference here is that the SQL executed will be SELECT * FROM Products WHERE Cost >= 25
.
IEnumerable<T>和IQuryable<T>的区别的更多相关文章
- 【转载】我也说 IEnumerable,ICollection,IList,List之间的区别
做C#的同学们,都知道,一类只能有一个继承类,但可以实现多个接口.这句话就告诉我们:IEnumerable,ICollection,IList,List区别了 首先我看看 IEnumerable: / ...
- IEnumerable,ICollection,IList,List之间的区别
做C#的同学们,都知道,一类只能有一个继承类,但可以实现多个接口.这句话就告诉我们:IEnumerable,ICollection,IList,List区别了 // 摘要: // 公开枚举器,该枚举器 ...
- 深入理解IEnumerable和IQueryable两接口的区别
from:http://blog.csdn.net/ydm19891101/article/details/50969323 无论是在ado.net EF或者是在其他的Linq使用中,我们经常会碰到两 ...
- IQueryable和IEnumerable以及AsEnumerable()和ToList()的区别
注意:本文背景为 Linq to sql .文中ie指代IEnumerable,iq指代IQueryable. IQueryable 和 IEnumerable 的区别 IQueryable 延时执行 ...
- 基础知识---IEnumerable、ICollection、IList、IQueryable
一.定义 IEnumerable public interface IEnumerable<out T> : IEnumerable ICollection public interfac ...
- 【开源】OSharp框架解说系列(5.1):EntityFramework数据层设计
OSharp是什么? OSharp是个快速开发框架,但不是一个大而全的包罗万象的框架,严格的说,OSharp中什么都没有实现.与其他大而全的框架最大的不同点,就是OSharp只做抽象封装,不做实现.依 ...
- ORM之EF初识
之前有写过ef的codefirst,今天来更进一步认识EF! 一:EF的初步认识 ORM(Object Relational Mapping):对象关系映射,其实就是一种对数据访问的封装.主要实现流程 ...
- C# 实战笔记
http://www.cnblogs.com/ymnets/p/3424514.html 学习点 关于IEnumerable和IQueryable两接口的区别 二者都是静态类 区另主要在: (1)所有 ...
- 从yield关键字看IEnumerable和Collection的区别
C#的yield关键字由来以久,如果我没有记错的话,应该是在C# 2.0中被引入的.相信大家此关键字的用法已经了然于胸,很多人也了解yield背后的“延迟赋值”机制.但是即使你知道这个机制,你也很容易 ...
随机推荐
- 阶段5 3.微服务项目【学成在线】_day05 消息中间件RabbitMQ_13.RabbitMQ研究-工作模式-header和rpc工作模式
header模式 header模式与routing不同的地方在于,header模式取消routingkey,使用header中的 key/value(键值对)匹配 队列. 案例: 根据用户的通知设置去 ...
- JavaScript里的原型(prototype), 原型链,constructor属性,继承
① __proto__ 和 constructor 属性是 对象 所独有的. ② prototype 属性是 函数 所独有的. ** JS里函数也是引用类型的对象,所以函数也有 __proto__ 和 ...
- 多个celery如何使用同一个redis做为broker?
曾经有个哥们提了一个这方面的requests,但是最终没有合入的celery中去,所以目前celery没有这个功能,祥见: https://github.com/celery/kombu/pull/9 ...
- STM32命名规则解析
- .Netcore 2.0 Ocelot Api网关教程(6)- 配置管理
本文介绍Ocelot中的配置管理,配置管理允许在Api网关运行时动态通过Http Api查看/修改当前配置.由于该功能权限很高,所以需要授权才能进行相关操作.有两种方式来认证,外部Identity S ...
- 我是如何提高工作效率的-工具篇(二)-listary
痛点: 还在为不能闪电速度搜索全盘文件.程序.无缝切换程序烦恼吗? 效果图: 功能1:搜索 各种文件.支持模糊搜索.全拼.文字首字母等模糊查询方式. (功能强大.尽情探索!) 痛点:文件好多啊,可 ...
- Web模糊测试:WFuzz的坑和快速入门
转载自 FreeBuf.COM 首先说下我对wfuzz这个工具的简单介绍和理解.工具主要是做web模糊测试,最开始做fuzz我是自己写个脚本配合一些常用工具来测,后来看见这款工具因为是比较简单吧,学习 ...
- linux下使用openssl和md5sum加密文件或者字符串
#openssl //在终端中输入openssl后回车. OpenSSL> md5 //输入md5后回车 123456 //接着输入123456,不要输入回车.然后按3次ctr ...
- C++.控制台_界面颜色
1.c++中system(_color )怎样用?-CSDN论坛.html(https://bbs.csdn.net/topics/390758320) 2. 2.1. 颜色属性由两个十六进制数字指定 ...
- java学习(东软睿道)2019-09-07(预课html基础)《随堂笔记》
1. 文件名称.html 2. 后缀表示文件类型.txt .doc .ppt 3. 标签<html> <head> <body> 显示内容 <font siz ...