I have two object models that looks like this:
public class MyObject
{
public List<SomeOtherObject> TheListOfSomeOtherObjects { get; set; }
}
public class SomeOtherObject
{
long SomeOtherObjectID { get; set; }
}
And I have a list of MyObjects called ListOfMyObjects from which I want to extract all the SomeOtherObjectID that are inside lists TheListOfSomeOtherObjects
I want to write something like this:
var ListOfAllSomeOtherObjectID = (from l in ListOfMyObjects
select l.SomeOtherObject.SomeOtherObjectID ).ToList();
It’s not working because of the syntax. How do I get a list of the nested lists?
Thanks for your suggestions.
You’re trying to flatten the nested lists:
If you then want to get a property of those objects, you’ll need a separate
Select()call: