LINQ: difference between Single(), First(), and Take(1)
来源:互联网 发布:苹果手机屏幕录像软件 编辑:程序博客网 时间:2024/06/08 19:21
LINQ provides a few different methods that return you a single object: Single(), First(), and Take(1).It took me a while, but I think I understand the difference: Single() operates on a collection of exactly one object and simply returns the object. First() operates on a collection of any number of objects and returns the first object. Take(1) operates on a collection of any number of objects and returns a collection containing the first object....
Linq提供了一些不同的返回单个对象的函数:Single(),First()和Take(1)。
Single():操作一个集合,同时强要求只有一个对象匹配,并返回这一个。
First():操作一个集合,可以有多个对象匹配,但是只返回第一个。
Take(1):操作一个集合,可以有对个对象匹配,单只返回第一个,但是这里返回的是一个集合,而不是单个的概念。
GridView1.DataSource = dataContext.Customers.Where(p => p.City.Length > 2 && p.CompanyName.Length > 5).First();
我想将查询出来的第一条数据绑定到GridView上,这样写不对,因为获得不了相关接口。请问该如何在一句内实现绑定?
GridView1.DataSource = dataContext.Customers.Where(p => p.City.Length > 2 && p.CompanyName.Length > 5).Take(1);
- LINQ: difference between Single(), First(), and Take(1)
- linq中的Single()、First()、Take(1) 区别
- linq中的Single()、First()、Take(1)
- linq中的Single()、First()、Take()
- The difference between (()) and ().
- difference between "<" and "<<"
- Linq: First,FirstOrDefault,Single,SingleOrDefault
- Difference Between typedef and #define
- Difference between PCDATA and CDATA
- Difference between CComPtr and CComQIPtr
- Difference between RVCT and GCCE
- Difference between RVCT and GCCE
- difference between slist and list.
- difference between stack and heap
- Difference between replace and translate
- Difference between PrintWriter and PrintStream
- difference between Cookie and Session
- Difference Between Buffer and Cache
- 资深黄金专家李鑫:独创7套算点理论震惊市场
- WebKit中的Chrome和ChromeClient
- android中获取context的多种方法的区别(this,getbascontext(),getApplicationcontext())
- eclipse 代码收缩和展开;设置快捷键
- I2C
- LINQ: difference between Single(), First(), and Take(1)
- oracle 在plsql中创建procedure并调用
- 字符编码乱码问题
- 20个项目托管站点推荐
- hbase安装配置(整合到hadoop)
- Window XP驱动开发(二) 环境搭建(VS2008+WDK+DDKWzard)及示例源码分析
- 黑马程序员 课后日记-集合方法
- SQL:having 用于排除某些数据的例子
- Makefile中的变量及条件判断的使用