【发布时间】:2021-08-02 15:17:06
【问题描述】:
我有三个不同类别的列表(MTR、AA、EIMS)。在所有三个类中,我都有共同的属性prefixid 和phasename。根据条件,我想按 Prefix 或 prefix and Phase 条件对类进行分组并创建字典。
我尝试以下面的方式实现,但由于没有隐式转换而出现无法确定表达式的错误。
如何做到这一点?
var mtrDct = revision.IsAllowToBorrow ?
mtrubilledTrxs.Where(x => x.AgrmntRevId == revId).GroupBy(x => x.Prefix.Id).ToDictionary(z => z.Key, z => z.ToList()) :
mtrubilledTrxs.Where(x => x.AgrmntRevId == revId).GroupBy(x => new { x.Prefix.Id, x.Phase.ShortName }).ToDictionary(z => z.Key, z => z.ToList());
var eimsDct = revision.IsAllowToBorrow ?
evunbilledTrxs.Where(x => x.AgrmntRevId == revId).GroupBy(x => x.Prefix.Id).ToDictionary(z => z.Key, z => z.ToList()) :
evunbilledTrxs.Where(x => x.AgrmntRevId == revId).GroupBy(x => new { x.Prefix.Id, x.Phase }).ToDictionary(z => z.Key, z => z.ToList());
var aaDct = revision.IsAllowToBorrow ?
aaunbilledTrxs.Where(x => x.AgrmntRevId == revId).GroupBy(x => x.Prefix.Id).ToDictionary(z => z.Key, z => z.ToList()) :
aaunbilledTrxs.Where(x => x.AgrmntRevId == revId).GroupBy(x => new { x.Prefix.Id, x.Phase.ShortName }).ToDictionary(z => z.Key, z => z.ToList());
获得这三个字典后,我需要从所有三个字典中获取不同的键。
最好的方法是什么。
【问题讨论】:
标签: c# dictionary