2015-09-04 13 views
5
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 

I risultati finali attesi sono ottenere un oggetto IEnumerable con 1.2, 2.3, 3.1, 4.2 che rappresenta il SubTierId di ciascun sottotitolo.Come ottenere oggetti secondari in base al valore usando linq?

SubSubTiers mySubSubTier = allTiers.Select(topTier => 
      topTier.SubTiers.Where(sbTier => sbTier.Id == topTier.SubTierId)); 

ma quello che succede è che ottengo questo tipo di ritorno.

IEnumerable<IEnumerable<SubSubTier>> 

Qual è il modo migliore in modo che ottengo solo un singolo IEnumerable del SubSubTier?

+2

è possibile utilizzare SelectMany al posto di Select – wudzik

+0

erano la mia risposta è stata utile? Avete altri problemi? – wudzik

+0

Sì, il trucco non è tornato subito. Grazie mille! :) – MichaelChan

risposta

4

È possibile utilizzare SelectMany al posto di Select

SubSubTiers mySubSubTier = allTiers.SelectMany(topTier => 
     topTier.SubTiers.Where(sbTier => sbTier.Id == topTier.SubTierId)); 

selezionerà subtiers in combinato IEnumerable invece di IEnumerable di IEnumerables

Problemi correlati