我正在嘗試從表中獲取記錄并將其轉換為字典,但在轉換為Dictionary<int, List<WorkpaperClientDetail>>使用 selectmany 運算子時出錯。
出現錯誤 - 運算式樹 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);
uj5u.com熱心網友回復:
[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);
轉載請註明出處,本文鏈接:https://www.uj5u.com/shujuku/530630.html
