【发布时间】:2020-01-11 22:52:57
【问题描述】:
我有这个模型:
public class AudienceInfo
{
public int Id { get; set; }
public string Departments { get; set; }
public List<CountOfDestination> CountOfDestinations { get; set; }
}
public sealed class CountOfDestination
{
public string DestinationName { get; set; }
public int? CountRoom { get; set; }
public int? CountOfFiles { get; set; }
}
还有 DB 中的这张表。
public class AudienceInfo : IModelWithId
{
public int Id { get; set; }
....
public RoomPurpose RoomPurpose { get; set; }
public List<AudienceInfo_File> Files { get; set; }
}
选择“部门”(条件)后,我得到一个数据列表。然后,我 GroupBy “RoomPurpose” 并得到 每行的“CountRoom” = DestinationName。这部分工作正常。 另外,我需要获取 CountOfFiles ...不知道该怎么做
return dbAudInfo
.Where(x => x.RightOfPreferentialUse.Id == Id)
.Select(x => new AudienceInfo
{
Departments = x.RightOfPreferentialUse.Name,
Date = date1,
CountOfDestinations = dbAudInfo
.GroupBy(z => new { z.RoomPurpose })
.Select(y => new CountOfDestination
{
DestinationName = y.Key.RoomPurpose.Name,
CountRoom = y.Count(z => z.RightOfPreferentialUse.Id == Id),
CountOfFiles = ?????????????????????????
}).ToList()
}).FirstOrDefaultAsync();
如何将 LINQ 查询中的列表与 GroupBy 连接起来。
【问题讨论】: