开发者

Linq - find element in nested collections

I have a generic list - Suppor开发者_StackOverflow社区tedTypeGroups.

Each SupportedTypeGroup has SupportedTypes property (generic list of SupportedType).

How to construct a Linq query to locate SupportedType with required name?


var result = SupportedTypeGroups
             .SelectMany(g => g.SupportedTypes)
             .FirstOrDefault(t => t.Name == "TypeName");


SupportedTypeGroups
  .SelectMany(s => s.SupportedTypes)
  .Where(s => s.name == "TheName");


Assuming SupportedTypes is an IEnumerable<SupportedType>

from g in SupportedTypeGroups
where g.SupportedTypes.Where(t => t.Name == "magicName")
select g;

Assuming SupportedTypes is just a SupportedType property

from g in SupportedTypeGroups
where g.SupportedTypes.Name == "magicName"
select g;

Asasuming you just want the SupportedType

from tg in SupportedTypeGroups
from t in tg.SupportedTypes
where t.Name == "magicName"
select t;
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜