我有
1)列表< objectA> objectAList
objectA有id,姓名,年龄,身高,体重
2)字典< string,List< ObjectB>> objectBDictionary;
对象B有id,姓名,地址,电子邮件
现在,我想提取objectAList和objectBDictionary之间的相关条目匹配(id和name)。
答案 0 :(得分:1)
我会尝试这样的事情:
// Initially, I would get a list of all objectB's in the lists of objectB that
// are contained in the Dictionary values.
List<ObjectB> objectsB = objectBDictionary.Select(x=>x.Value)
.SelectMany(y=>y);
// Then, I would make the join.
var result = from a in objectListA
join b in objectsB
on new { a.id, a.name } equals { b.id, b.name }
select new
{
Id = a.id,
Name = a.name,
Height = a.height,
Weight = a.weight,
Address = b.address,
Email = b.email
};