linq 分组
var data = from r in listRecords
group r by
new
{
r.CampaignId,
r.CityId,
r.Gift_DistributorId,
r.ProductGiftId, FirstQuantity = listRecords.Where(a => a.CampaignId == r.CampaignId
&& a.CityId == r.CityId
&& a.Gift_DistributorId == r.Gift_DistributorId
&& a.ProductGiftId == r.ProductGiftId).Sum(c => c.FirstQuantity), Premium = listRecords.Where(a => a.CampaignId == r.CampaignId
&& a.CityId == r.CityId
&& a.Gift_DistributorId == r.Gift_DistributorId
&& a.ProductGiftId == r.ProductGiftId).Sum(c => c.Premium)
} into g
select g.Key
;
参考 http://stackoverflow.com/questions/5231845/c-sharp-linq-group-by-on-multiple-column //修改后
var data2 = from r in listRecords
group r by
new
{
r.CampaignId,
r.CityId,
r.Gift_DistributorId,
r.ProductGiftId, } into g
select new
{
g.Key.CampaignId,
g.Key.CityId,
g.Key.Gift_DistributorId,
g.Key.ProductGiftId,
FirstQuantity = g.Sum(a => a.FirstQuantity),
Premium = g.Sum(a => a.Premium)
};
linq 分组的更多相关文章
- Linq分组功能
Linq在集合操作上很方便,很多语法都借鉴自sql,但linq的分组却与sql有一定的区别,故整理发布如下. 1. Linq分组 分组后以Key属性访问分组键值. 每一组为一个IEnumberAbl ...
- Linq分组操作之GroupBy,GroupJoin扩展方法源码分析
Linq分组操作之GroupBy,GroupJoin扩展方法源码分析 一. GroupBy 解释: 根据指定的键选择器函数对序列中的元素进行分组,并且从每个组及其键中创建结果值. 查询表达式: var ...
- Linq分组,linq方法分组
Group在SQL经常使用,通常是对一个字段或者多个字段分组,求其总和,均值等. Linq中的Groupby方法也有这种功能.具体实现看代码: 假设有如下的一个数据集: 01.public class ...
- Linq分组查询统计
这里介绍Linq使用Group By和Count得到每个CategoryID中产品的数量,Linq使用Group By和Count得到每个CategoryID中断货产品的数量等方面. 学经常会遇到Li ...
- C# 泛型分组和Linq分组的异同
没什么好说的,因为用的到,所以作个记录, 代码如下: using System; using System.Collections.Generic; using System.Linq; using ...
- c# linq 分组groupby
转载: https://www.cnblogs.com/cncc/p/9846390.html 一.先准备要使用的类: 1.Person类: class Person { public string ...
- linq分组求和_实体类和datatable
1.数据分组求合,分别用的实体类以及datatable来分组求合,还有分组求和之后的如何取值 //实体类版本 List<ProgramTimeModel> TotalAllList = G ...
- 示例, linq分组
public class HIS_CLIREGISTER : BaseModel{ private String _FBCODE;[StringLength(8)]/// <summary> ...
- LINQ分组取出第一条数据
Person1: Id=, Name="Test1" Person2: Id=, Name="Test1" Person3: Id=, Name="T ...
- C# DataTable 通过Linq分组
datatable我们是经常使用到的,但是需要对数据进行分组,具体代码如下: var result = dt.AsEnumerable().GroupBy(f => new { type = f ...
随机推荐
- nyoj 911 Registration system(map)
Registration system 时间限制:1000 ms | 内存限制:65535 KB 难度:2 描述 A new e-mail service "Berlandesk&q ...
- MySql 执行计划解读
说明 解读执行计划l对于我们日常工作中慢sql的分析和调优有很大帮助,同时在解读的过程中也能知道如何规避慢sql 建议需要了解join匹配原理的知识:https://www.cnblogs.com/L ...
- WEB开发----springboot的登录拦截机制
如果是一个后台的管理项目的,有些东西是不能直接就可以访问的,必须要登录才可以进去,所以就需要进行登录拦截,只有登录过的用户才可以正常访问. 登录拦截是不会拦截jsp页面的方法,所以我们需要在Contr ...
- [JavaEE] JTA, Java Transaction API, Repository for DB opreations
Mainly two things: 1. For all the creating and deleting opreations for the DB, we want to use 'REQUI ...
- HDU 1814 Peaceful Commission(2-sat 模板题输出最小字典序解决方式)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1814 Problem Description The Public Peace Commission ...
- 如何删除 mac 系统信息下的安装记录
方法:在finder中:Command+Shift+G 打开 /Library/Receipts/InstallHistory.plist 所有的记录都在 InstallHistory.plist 文 ...
- JDBC高级特性(一)结果集,批量更新
一.ResultSet的高级特性 1 可滚动ResultSet 1)向前和向后滚动 滚动特性 在JDBC初期版本号中, ResultSet仅能向前滚动 在JDBC兴许版本号中, ResultSet默认 ...
- PX4/Pixhawk---高速成为开发人员(Windows)
1 高速成为开发人员新手教程(翻译)---官方 1.1 编译环境之版本号控制系统 (1)安装MSysGIT 安装完毕后,配置GIT. 安装注意 安装过程中除了以下一步外,其它的步骤都採用默认安 ...
- [1525] Cow Xor
问题描述 农民约翰在喂奶牛的时候被另一个问题卡住了.他的所有N(1 <= N <= 100,000)个奶牛在他面前排成一行(按序号1..N的顺序),按照它们的社会等级排序.奶牛#1有最高的 ...
- EditText 光标的颜色
EditText有一个属性:android:textCursorDrawable,这个属性是用来控制光标颜色的 android:textCursorDrawable="@null&quo ...