I need to get a list of Decades that has a list of Songs.
The kicker is I need a list of ACTIVE Decades along with ACTIVE songs.
Here are my models:
Here is what I have so far:
Decades = await _context.Decades
.Include(x => x.Songs)
.Where(x => x.Active == true && x.Songs.Any(s => s.Active == true))
.OrderBy(x => x.DecadeId)
.ToListAsync()
But what I get are Decades that are ACTIVE but the Songs don't matter - I get them all no matter the ACTIVE flag.
Thoughts?
Here is the solution I came up with - with the help from Jawad below - for those that may find it useful:
Decades = await _context.Decades
.Include(x => x.Songs)
.Where(x => x.Active == true)
.OrderBy(x => x.DecadeId)
.Select(x => new Decade()
{
DecadeId = x.DecadeId,
DecadeText = x.DecadeText,
DecadeExtended = x.DecadeExtended,
Description = x.Description,
Active = x.Active,
Added = x.Added,
Songs = x.Songs
.Where(s => s.Active == true).ToList()
}).ToListAsync()