一句简单的linq group by 语句

拼接筛选条件

 // 拼接条件
            Expression<Func<ProductLangDailySummaryDetail, bool>> whereCondition = p => 1 == 1;
            if (dateTimeStart != null) whereCondition = whereCondition.And(m => m.SummaryDate >= dateTimeStart);
            if (dateTimeEnd != null) whereCondition = whereCondition.And(m => m.SummaryDate <= dateTimeEnd);

通过ProductType和Language分组,得到分组后的对象列表      


            var ProductLangDailySummaryDetailGroup = _productLangDailySummaryDetailRepository.Query().Where(whereCondition).GroupBy(x => new
            {
                x.ProductType,
                x.Language
            }).Select(m => new { ProductType = m.Key.ProductType, Language = m.Key.Language, Count = m.Count() }).ToList();

 

posted @ 2018-12-13 23:03  清晨时光  阅读(436)  评论(0编辑  收藏  举报