0

I got following structure:

Class A has a member: List<ClassB>

Class B has a member: List<ClassC>

Who is it possible to get for one specific object of class A one specific object of List<B> and all of it's objects in List<ClassC>?

In a other way: How can I get the List<ClassC> for a specific ClassB?

2
  • Possible duplicate of Difference Between Select and SelectMany Commented Apr 5, 2017 at 17:50
  • Are you using EF and are those classes entities of your model? How do you know which ClassB object you want to get? Commented Apr 5, 2017 at 17:51

3 Answers 3

1

Try:

var a_list = new List<A>();
var c_list = a_list.First(a => [your criteria here])
                   .b_list
                   .First(b => [your criteria here])
                   .c_list;
Sign up to request clarification or add additional context in comments.

Comments

0

You can try ( to avoid any exceptions)

 ClassA classAItem = yourClassAList.FirstOrDefault({your A condition})

    if(classAItem != null)
    {
      ClassB  classBItem = classAItem.yourClassBList.FirstOrDefault({your B condition});

      if(classBItem != null)
      {
        List<ClassC> classCItem = classBItem.yourClassCList);
      }
}

Comments

0

Found the solution:

_db.ClassA.Include(b => b.ClassB).ThenInclude(c => c.ClassC);

Thanks for your answers!

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.