LINQ to SQL收藏
1、LINQ group by分組彙總
public class TestData
{
public string Name{get;set;}
public int Count { get; set; }
public string BatNum { get; set; }
}
protected void Click(object sender, EventArgs e)
{
List<TestData> list = new List<TestData>();
list.Add(new TestData() { Name = "A", Count = 3, BatNum = "001" });
list.Add(new TestData() { Name = "A", Count = 3, BatNum = "001" });
list.Add(new TestData() { Name = "A", Count = 3, BatNum = "002" });
list.Add(new TestData() { Name = "b", Count = 3, BatNum = "001" });
list.Add(new TestData() { Name = "b", Count = 6, BatNum = "002" });
list.Add(new TestData() { Name = "b", Count = 3, BatNum = "003" });
list.Add(new TestData() { Name = "b", Count = 5, BatNum = "001" });
var query = from l in list
group l by new { l.Name, l.BatNum } into g
select new
{
Name = g.Key.Name,
Count = g.Sum(a => a.Count),
BatNum = g.Key.BatNum
};
string result = "";
foreach (var q in query)
{
result += "Name=/"" + q.Name + "/"," + "Count=/"" + q.Count + "/"," + "BatNum=/"" + q.BatNum + " /"<br />";
}
Response.Write(result);
}
//結果:
Name="A",Count="6",BatNum="001 "
Name="A",Count="3",BatNum="002 "
Name="b",Count="8",BatNum="001 "
Name="b",Count="6",BatNum="002 "
Name="b",Count="3",BatNum="003 "
2、
相關文章
- ASP.Net LINQ to SQl查詢ASP.NETSQL
- 【轉】LINQ to SQL語句(1)之WhereSQL
- Linq
- SQL調優13連問,收藏好!SQL
- [譯]LINQ TO SQL 介紹(定義資料模型類) – Part.2SQL模型
- Lambda、Linq
- linq介紹
- 瞭解LINQ
- linQ基礎
- [go-linq]-Go的.NET LINQ式查詢方法Go
- LinQ查詢基礎(三)LINQ to ADO.net(1)LINQ to DataSet實現複雜資料查詢
- LINQ 動態排序排序
- Linq使用Group By 1
- Linq之左聯接
- Linq 日期轉換
- 15000 字的 SQL 語句大全,收藏落灰款!SQL
- LINQ擴充套件方法套件
- linq學習筆記筆記
- C# 之 Linq to XmlC#XML
- Linq之分組聯接
- Linq sum()時遇到NULLNull
- Linq 綜合寫法
- 【Linq】常用語法彙總
- 強大的動態 LINQ 庫
- LINQ SelectMany的應用場景
- 史上最全:PostgreSQL DBA常用SQL查詢語句(建議收藏學習)SQL
- linq介紹及工作中應用兩例——左聯與內聯,linq迴圈方法
- System.Linq.Dynamic字串轉委託字串
- linq中AsEnumerable和AsQueryable的區別
- C#規範整理·集合和LinqC#
- C# LINQ (語言整合查詢)C#
- Linq查詢之多個排序條件排序
- Linq兩個from查詢條件
- C#版本LINQ增強開源庫C#
- JSON.NET與LINQ序列化示例JSON
- Linq查詢語法與擴充方法
- 收藏夾
- 歌曲收藏
- C#-聽說有人不推薦使用Linq!?C#