I have three objects:
Artist, Albums and Track.
The artists are stored in a List<Artist> and inside the Artist object there's another list for the artist's Albums (List<Albums>) And in the Album object there is yet another list for the tracks (List<Track>)
How would you go about selecting all the tracks at once?
Is there any way to do:
TrackList.AddRange(ArtistList.Albums.Tracks);
Until now I have been doing this:
foreach (Artist artist in artistlist)
{
if (artist.Albums != null)
{
ForEach(Album album in artist.Albums)
{
Context.AddRange(album.Tracks);
}
}
}
You could try
Or something to that effect. I'm a little rusty on
SelectMany, but I'm fairly confident it can be used here.I'm also not sure whether your
nullcheck is needed here, too. But you can add aWhereclause before theSelectMany.