Linq语法
来源:互联网 发布:俄罗斯运营商网络制式 编辑:程序博客网 时间:2024/05/22 00:28
一、Linq定义:
LINQ,语言集成查询(Language Integrated Query)是一组用于c#和Visual Basic语言的扩展。它允许编写C#或者Visual Basic代码以查询数据库相同的方式操作内存数据。
二、Linq语法:
1.where
var where = lstPriceHis.Where(p => p.ProductPrice > 3700).ToList();var where2 = (from p in lstPriceHis where p.ProductPrice > 3700 select p).ToList();
var where3 = lstPriceHis.Where(p => p.PriceId == "1" || p.PriceId.Contains("2")).ToList();
var where4 = lstPriceHis.Where(p => p.PriceId == "1" && p.PriceId.Contains("2")).ToList();
2.max,min,count,sum
var max = lstPriceHis.Max(p => p.ProductPrice);var min = lstPriceHis.Min(p => p.ProductPrice);
var count = lstPriceHis.Count();
var sum = lstPriceHis.Sum(p => p.ProductPrice);
var sum2 = "select sum(ProductPrice) from lstPriceHis";
3.orderby
var orderby = from p in lstPriceHis where p.ProductPrice > 3700 orderby p.ProductPrice descending select p;var orderby2 = lstPriceHis.Where(p => p.ProductPrice > 3800).OrderByDescending(p => p.ProductPrice).ToList();
4.top
var top = lstPriceHis.FirstOrDefault();var top2 = "select top(1) * from lstPriceHis";
5.skip,take
var skip = lstPriceHis.OrderByDescending(p => p.ProductPrice).Skip(2).ToList();var take = lstPriceHis.OrderByDescending(p => p.ProductPrice).Skip(2).Take(2).ToList();
6.like
var contains = lstPriceHis.Where(p => p.ProductName.Contains("液化"));7.groupby
var groupby = lstPriceHis.GroupBy(p => p.ProductName).ToList();foreach (var g in groupby)
{
var keyg = g.Key;
var sumg = g.Sum(a => a.ProductPrice);
}
8.join
var join = lstPriceHis.Join(lstCompany, p => p.CompanyId, r => r.CompanyId, (p, r) => p).OrderByDescending(p => p.ProductPrice).ToList();
三、参考:
1.http://www.cnblogs.com/knowledgesea/p/3897665.html
2.http://www.cnblogs.com/liulun/archive/2013/02/26/2909985.html
阅读全文
0 0
- LINQ语法
- LINQ语法
- Linq语法
- Linq语法
- linq语法
- Linq 语法
- Linq语法
- Linq语法
- linq 语法lambpa语法总结
- LINQ语法 收藏
- Linq基本语法
- #3.0 LINQ 查询语法
- LINQ中的Aggregate语法
- Linq基本语法
- Linq语法构成
- XML LINQ语法
- Linq基本语法概述
- linq to sql 语法
- 使用RANSAC算法基于几何模型分割图像
- C语言基础-二维数组13
- ARM Cortex-M3核LPC1768的μCOS-II的移植练习-1
- Java线程的生命周期以及sleep方法应用
- Div被鼠标划过时其背景色变色的第六种方式
- Linq语法
- Redis集群设置密码
- C# #region
- 模态和非模态对话框
- ios提审报错:No suitable application records were found. Verify your bundle identifier 'xx' is correct
- C++学习笔记(三)
- lintcode(379)将数组重新排序以构造最小值
- Session(会话)简单理解
- 完全卸载MySQL