我有一个通用列表 - SupportedTypeGroups。
每个SupportedTypeGroup都有SupportedTypes属性(SupportedType的通用列表)。
如何构建Linq查询以找到具有所需名称的SupportedType?
答案 0 :(得分:9)
var result = SupportedTypeGroups
.SelectMany(g => g.SupportedTypes)
.FirstOrDefault(t => t.Name == "TypeName");
答案 1 :(得分:5)
SupportedTypeGroups
.SelectMany(s => s.SupportedTypes)
.Where(s => s.name == "TheName");
答案 2 :(得分:1)
假设SupportedTypes
是IEnumerable<SupportedType>
from g in SupportedTypeGroups
where g.SupportedTypes.Where(t => t.Name == "magicName")
select g;
假设SupportedTypes
只是SupportedType
属性
from g in SupportedTypeGroups
where g.SupportedTypes.Name == "magicName"
select g;
Asasuming你只需要SupportedType
from tg in SupportedTypeGroups
from t in tg.SupportedTypes
where t.Name == "magicName"
select t;