我试图从表中获取记录并将其转换为字典,但在使用selectmany操作符转换为Dictionary<int, List<WorkpaperClientDetail>>
时出现错误。
得到错误-表达式树lambda可能不包含字典初始化项。
var asd = uow.WorkpaperRepo.GetAllNoTracking(expression)
.SelectMany(wps => new Dictionary<int, List<WorkpaperClientDetail>>
{
[wps.WorkpaperId] = wps.AccountMap.AccountMappings.Select(y => new WorkpaperClientDetail
{
AccountName = y.ClientAccount.Description,
AccountNumber = y.ClientAccount.Code
}).ToList()
}).ToDictionary(d => d.Key, d => d.Value);
以[wps.WorkpaperId] = wps.AccountMap ...
开头的字典初始化器?我不知道你想在这里做什么,但这应该像预期的那样工作:
Dictionary<int, List<WorkpaperClientDetail>> asd = uow.WorkpaperRepo.GetAllNoTracking(expression)
.Select(wps => new{ wps.WorkpaperId, ClientList = wps.AccountMap.AccountMappings
.Select(y => new WorkpaperClientDetail
{
AccountName = y.ClientAccount.Description,
AccountNumber = y.ClientAccount.Code
})
.ToList() })
.ToDictionary(x => x.WorkpaperId, x => x.ClientList);