Top Tier Object
        SubTier Objects
            SubSubTier Objects 1.1,1.2,1.3 : SubTierId = 2
            SubSubTier Objects 2.1,2.2,1.3 : SubTierId = 3
        SubTier Objects
            SubSubTier Objects 3.1,3.2,3.3 : SubTierId = 1
            SubSubTier Objects 4.1,4.2,4.3 : SubTierId = 2
Expected end results is to get an IEnumerable with 1.2, 2.3, 3.1, 4.2 which represents the SubTierId of each subTier.
SubSubTiers mySubSubTier = allTiers.Select(topTier => 
            topTier.SubTiers.Where(sbTier => sbTier.Id == topTier.SubTierId));
but what happens is I get this return type.
IEnumerable<IEnumerable<SubSubTier>>
What is the best way so that I just get a single IEnumerable of the SubSubTier?
You can use SelectMany instead of Select
SubSubTiers mySubSubTier = allTiers.SelectMany(topTier => 
        topTier.SubTiers.Where(sbTier => sbTier.Id == topTier.SubTierId));
it will select subtiers into combined IEnumerable instead of IEnumerable of IEnumerables
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With