Linq的基础2
var 构建匿名类型1 = from c in ctx.GetTable<Customers>()
select new
{
城市 = c.City,
名字 = c.Name
};
var 构建匿名类型2 = from emp in ctx.GetTable<Customers>()
select new
{
城市 = emp.City,
名字 = emp.Name
};
var 多条件 = from c in ctx.GetTable<Customers>()
where c.Name == "Jay" && c.City == "雷州"
select new
{
名字 = c.City,
城市 = c.City
};
var 排序 = from c in ctx.GetTable<Customers>()
where c.City == "雷州"
orderby c.Name descending, c.City ascending
select new
{
名字 = c.Name,
城市 = c.City
};
//按照每页 10 条记录,查询第二页的顾客
var 分页 = (from c in ctx.GetTable<Customers>() select c).Skip(10).Take(10);
//根据顾客的国家分组,查询顾客数大于 5 的国家名和顾客数
var 一般分组 = from c in ctx.GetTable<Customers>()
group c by c.City into g
where g.Count() > 5
orderby g.Count() descending
select new
{
国家=g.Key,
顾客数=g.Count()
};
//根据国家和城市分组,查询顾客覆盖的国家和城市
var 匿名类型分组 = from c in ctx.GetTable<Customers>()
group c by new { c.City, c.Name } into g
orderby g.Key.City, g.Key.Name
select new
{
国家 = g.Key.Name,
城市 = g.Key.City
};
var 过滤相同项 = (from c in ctx.GetTable<Customers>() orderby c.Name select c.Name).Distinct();
var 连接并且过滤相同项 = (from c in ctx.GetTable<Customers>()
where c.City.Contains("A")
select c)
.Union(from c in ctx.GetTable<Customers>()
where c.Name.StartsWith("A")
select c).OrderBy(c => c.City);
var 连接并且不过滤相同项 = (from c in ctx.GetTable<Customers>()
where c.City.Contains("A")
select c).Concat
(from c in ctx.GetTable<Customers>() where c.City.StartsWith("A") select c)
.OrderBy(c => c.City);
//查询城市是 A 打头的顾客和城市包含 A 的顾客的交集,并按照顾客名字排序
var 取相交项 = (from c in ctx.GetTable<Customers>()
where c.City.Contains("A")
select c).Intersect
(from c in ctx.GetTable<Customers>()
where c.City.StartsWith("A")
select c).OrderBy(c => c.City);
//查询城市包含 A 的顾客并从中删除城市以 A 开头的顾客,并按照顾客名字排序
var 排除相交项 = (from c in ctx.GetTable<Customers>()
where c.City.StartsWith("A")
select c).Except
(from c in ctx.GetTable<Customers>()
where c.Name.StartsWith("A")
select c).OrderBy(c => c.Name);
//查询订单数超过 5 的顾客信息
var 子查询 = from c in ctx.GetTable<Customers>()
where
(from o in ctx.GetTable<Customers>()
group o by o.CustomerID into o
where
o.Count() > 5
select o.Key).Contains(c.CustomerID)
select c;
//查询指定城市中的客户
var in操作 = from c in ctx.GetTable<Customers>()
where new string[] { "B", "A", "C" }.Contains(c.City)
select c;
//内连接,没有分类的产品查询不到
var innerjoin = from p in ctx.GetTable<Customers>()
join c in ctx.GetTable<Customers>()
on p.CustomerID equals c.CustomerID
select p.Name;
//外连接,没有分类的产品也能查询到
var leftjoin = from p in ctx.GetTable<Customers>()
join c in ctx.GetTable<Customers>()
on p.City equals c.City
into pro
from x in pro.DefaultIfEmpty()
select p.Name;
var 单结果集存储过程 =
from c in ctx.sp_singleresultset()
where c.Name.StartsWith("A")
select c;
var 多结果集存储过程 = ctx.sp_multiresultset();
var Customer = 多结果集存储过程.GetResult<Customers>();
var Employees = 多结果集存储过程.GetResult<Employee>();
Linq的基础2的更多相关文章
- LinQ 语法基础
LINQ (Language-Integrated Query,语言集成查询). LINQ to Objects.LINQ to SQL.LINQ to DataSet和LINQ to XML,它们分 ...
- C#语法之Linq查询基础二
上篇C#语法之Linq查询基础一基本把Linq介绍了一下,这篇主要是列举下它的几个常见用法. 在用之前先准备些数据,新建了两个类Student.Score,并通过静态方法提供数据. using Sys ...
- LINQ查询基础
一.什么是LINQ LINQ是Language Integrate Query的缩写,意为语言集成查询,是微软在.Net Framework 4.5版中推出的主要特性之一. 它为开发人员提供了统一的数 ...
- C#语法之Linq查询基础一
Linq做.Net开发的应该都用过,有些地方很复杂的逻辑用Linq很方便的解决.对于Linq to object.Linq to xml.Linq to sql.Linq to Entity(EF)都 ...
- Linq 操作基础
参考资料: LINQ系列:LINQ to DataSet的DataTable操作 List<T>转换为DataTable C# DataTable 和List之间相互转换的方法 Linq中 ...
- Linq一 基础知识
1.什么是Linq 他是VS2008(.net framework 3.5)之后一项重大的突破 全程Lnaguage Integrated Query,可以成为数据迭代器. 主要有以下5大块组成: L ...
- Linq语句基础
using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.T ...
- LINQ的基础使用方法
//新建一个项目 //项目下新建一个App_Code文件夹 //在文件夹内添加一个LINQ TO SQL,这个操作就相当于创建了一个实体类 //连接数据库后把表拖入到服务器资源管理器中 //创建数据访 ...
- [.net 面向对象编程基础] (19) LINQ基础
[.net 面向对象编程基础] (19) LINQ基础 上两节我们介绍了.net的数组.集合和泛型.我们说到,数组是从以前编程语言延伸过来的一种引用类型,采用事先定义长度分配存储区域的方式.而集合是 ...
随机推荐
- 利用java反射机制对方法进行调用
http://blog.csdn.net/coolcoffee168/article/details/5835143
- Core Data (一)备
序 恩,用Core Data也有一段时间了.大大小小的坑也都坑过了.重来没有认真的记录一次.这次需要好好的理一理Core Data.就当一次绝好的机会记录下来.也为了自己加深认识. 为什么要用Core ...
- [Google Code Jam (Round 1A 2008) ] A. Minimum Scalar Product
Problem A. Minimum Scalar Product This contest is open for practice. You can try every problem as ...
- Oracle case用法
1:update 时做检查使用update mw_contract set payTimes=( case else payTimes end )'; 2:select时使用 select case ...
- hdu 1811 Rank of Tetris
http://acm.hdu.edu.cn/showproblem.php?pid=1811 拓扑排序和并差集 #include <cstdio> #include <queue&g ...
- JAVA字符串转日期或日期转字符串
文章中,用的API是SimpleDateFormat,它是属于java.text.SimpleDateFormat,所以请记得import进 来! 用法: SimpleDateFormat sdf = ...
- 【转】Android源码下载过程的一些注意事项
原文网址:http://www.360doc.com/content/14/0113/11/11948835_344809459.shtml 其它一些事项说明: 1.在源代码下载过程中,我们在源代码下 ...
- 理解 Linux 配置文件分类和使用
理解 Linux 配置文件分类和使用 本文说明了 Linux 系统的配置文件,在多用户.多任务环境中,配置文件控制用户权限.系统应用程序.守护进程.服务和其它管理任务.这些任务包括管理用户帐号.分配磁 ...
- Java 自定义实现 LRU 缓存算法
背景 LinkedHashMap继承自HashMap,内部提供了一个removeEldestEntry方法,该方法正是实现LRU策略的关键所在,且HashMap内部专门为LinkedHashMap提供 ...
- FlexComboBoxTree
在我的CSDN资源中有项目工程文件.下载导入工程即可看到效果,下面是地址. http://download.csdn.net/detail/cym_lmy/6326053 MyCombBoxTree1 ...