From what you describe:
var neueLieferanten = Bestellpositionen.Where(bp => bp.SelectedArtikel != null)
.SelectMany(bp => bp.SelectedArtikel.LieferantenArtikel)
.Select(la => la.Lieferant);
The SelectMany takes e.g. 10 List<LieferantenArtikel>
inside 10 Bestellpositionen.SelectedArtikel
s and turns them into a single List of LieferantenArtikel
, from which the Select
then extracts the Lieferant
property
You can structure it slightly differently for the same result:
var neueLieferanten = Bestellpositionen.Where(bp => bp.SelectedArtikel != null)
.SelectMany(bp => bp.SelectedArtikel.LieferantenArtikel
.Select(la => la.Lieferant)
);
I presented it this way to outline that really, the only change is the position of the bracket.. We're either turning a list of lists into a single list and then extracting a property, or we're extracting a property from a list in a list, and then turning it into a single list; use whichever way round appeals to your understanding more (I prefer the former)