c# - Select all objects in a list -
i have 3 objects:
artist, albums , track.
the artists stored in list<artist> , inside artist object there's list artist's albums (list<albums>) , in album object there yet list tracks (list<track>)
how go selecting tracks @ once?
is there way do:
tracklist.addrange(artistlist.albums.tracks); until have been doing this:
foreach (artist artist in artistlist) { if (artist.albums != null) { foreach(album album in artist.albums) { context.addrange(album.tracks); } } }
you try
tracklist.addrange( artistlist.selectmany(a => a.albums) .selectmany(a => a.tracks)) or effect. i'm little rusty on selectmany, i'm confident can used here.
i'm not sure whether null check needed here, too. can add where clause before selectmany.
Comments
Post a Comment