EntityFramework Linq 按年月统计查询
来源:互联网 发布:织梦小说源码 编辑:程序博客网 时间:2024/06/05 17:25
Expression<Func<Operator, bool>> wh = c => c.DimissionId != null;DateTime dtValueStart = DateTime.MinValue; DateTime dtValueEnd = DateTime.MinValue; if (!string.IsNullOrEmpty(startdate) && DateTime.TryParse(startdate, out dtValueStart)) { //重置为当月第一天 dtValueStart = new DateTime(dtValueStart.Year, dtValueStart.Month, 1); wh = wh.And(c => DbFunctions.TruncateTime(c.DimissionDate) >= DbFunctions.TruncateTime(dtValueStart)); } if (!string.IsNullOrEmpty(enddate) && DateTime.TryParse(enddate, out dtValueEnd)) { //重置为当月最后一天 dtValueEnd = new DateTime(dtValueEnd.Year, dtValueEnd.Month, 1).AddMonths(1).AddDays(-1); wh = wh.And(c => DbFunctions.TruncateTime(c.DimissionDate) <= DbFunctions.TruncateTime(dtValueEnd)); }var result = operatorService.GetByFilter(wh).GroupBy(c => new { c.DimissionDate.Value.Year, c.DimissionDate.Value.Month }).Select(g => new DimissionYearMonthlyVM { Year = g.Key.Year, Month = g.Key.Month, DimissionQty = g.Count() }).OrderBy(c => new { c.Year, c.Month }).ToList();
1、日期查询条件需要使用
DbFunctions.TruncateTime
转换一下
2、统计查询取值字段按照GroupBy中的字段
0 0
- EntityFramework Linq 按年月统计查询
- 数据库按年月查询语句
- MYSQL按年、月查询记录
- Oracle 按年或月进行统计
- oracle 按年,,,季度,,,月,,,,周,,,统计
- Oracle 按年或月进行统计
- SQL数据库。按年,月,日查询
- SQL查询按年、月累计求和
- LINQ分组查询统计
- LINQ分组查询统计
- 按年月统计并行列转换(ms sqlserver2005)
- Mysql 根据时间戳按年月日分组统计
- Mysql 根据时间戳按年月日分组统计
- Mysql 根据时间戳按年月日分组统计
- mysql中按年月统计的一些命令性能比较
- Mysql 根据时间戳按年月日分组统计
- Mysql 根据时间戳按年月日分组统计
- 根据时间 或 时间戳 按年月日分组统计
- JVM 性能调优实战之:一次系统性能瓶颈的寻找过程
- 通过Python画六角星
- 文件系统之 簇&块
- 一次非常有意思的 SQL 优化经历
- ElasticSearch java API - 聚合查询
- EntityFramework Linq 按年月统计查询
- 15章 上机2
- 那些必须知道的ADB命令
- 蓝鸥零基础学习HTML5第五讲 CSS的基础样式
- Remix OS 安装及初次使用心得
- 学习tomcat之通过shell批量管理多个tomcat
- Unity3D follow.
- iOS APP图标一键生成
- lua定时器与定时任务的接口设计