C# 请将下列表用lambda按照ServiceDate,ServiceBranchCode,ClueID,ProjectType,ServiceProjectTemplateID分组并计算ServiceCount,SaleAmount总和,并查出该表所有字段的数据 CREATE TABLE dbo.ReportConsultantAchievementDetail( ID int IDENTITY(1,1) NOT NULL, CreatedBy varchar(16) NOT NULL, CreatedDate datetime NOT NULL, ModifiedBy varchar(16) NOT NULL, ModifiedDate datetime NOT NULL, HasDeleted bit NOT NULL, OrderCode varchar(20) NOT NULL, BranchCode varchar(16) NOT NULL, ServiceDate datetime NOT NULL, ClueID int NOT NULL, ServiceProjectTemplateID int NOT NULL, CustName nvarchar(32) NOT NULL, ItemCode varchar(16) NOT NULL, ItemName nvarchar(32) NOT NULL, ItemClass varchar(2) NOT NULL, IsCooperation int NOT NULL, CooperationName nvarchar(32) NOT NULL, ProjectType int NOT NULL, Source int NOT NULL, SourceID int NOT NULL, ServiceCount decimal(18,2) NOT NULL, OriginalAmount decimal(18,2) NOT NULL, Discount decimal(18,2) NOT NULL, SaleAmount decimal(18,2) NOT NULL, ConsultantUserCode varchar(16) NOT NULL, ServiceBranchName nvarchar(16) NOT NULL, ServiceBranchCode varchar(16) NOT NULL, Remark nvarchar(300) NULL, ExamineStatus int NOT NULL, ExamineTime datetime NULL, ExamineBy varchar(16) NULL )
时间: 2024-03-11 09:49:16 浏览: 58
可以使用以下代码实现:
```
var result = dbContext.ReportConsultantAchievementDetail
.GroupBy(x => new { x.ServiceDate, x.ServiceBranchCode, x.ClueID, x.ProjectType, x.ServiceProjectTemplateID })
.Select(group => new {
group.Key.ServiceDate,
group.Key.ServiceBranchCode,
group.Key.ClueID,
group.Key.ProjectType,
group.Key.ServiceProjectTemplateID,
ServiceCount = group.Sum(x => x.ServiceCount),
SaleAmount = group.Sum(x => x.SaleAmount),
group.First().CreatedBy,
group.First().CreatedDate,
group.First().ModifiedBy,
group.First().ModifiedDate,
group.First().HasDeleted,
group.First().OrderCode,
group.First().BranchCode,
group.First().CustName,
group.First().ItemCode,
group.First().ItemName,
group.First().ItemClass,
group.First().IsCooperation,
group.First().CooperationName,
group.First().Source,
group.First().SourceID,
group.First().OriginalAmount,
group.First().Discount,
group.First().ConsultantUserCode,
group.First().ServiceBranchName,
group.First().Remark,
group.First().ExamineStatus,
group.First().ExamineTime,
group.First().ExamineBy
});
```
阅读全文