7

I have a generic list - SupportedTypeGroups.

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

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

3 Answers 3

12
var result = SupportedTypeGroups
             .SelectMany(g => g.SupportedTypes)
             .FirstOrDefault(t => t.Name == "TypeName");
Sign up to request clarification or add additional context in comments.

Comments

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

Comments

1

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;

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.