I have a collection called Albums with objects from the class Album. This class has a property Songs, which is a collection of Song objects. Each Song has an unique Id.
public IQueryable<Album> Albums
public class Album
{
...
public virtual ICollection<Song> Songs { get; set; }
...
}
public class Song
{
public int Id { get; set; }
...
}
Is it possible, using Linq, to find a Song in the Album collection? I have no idea how, I am new to Linq.
I tried a bit:
Albums.FirstOrDefault(a => a.Songs.Id == id);
Thanks a lot,
Vincent
The SelectMany will create a flattened list of all songs for all albums allowing you to then select the first with the appropriate id.