public IEnumerable <MusicContract> GetMusicContracts(ProductFilter filter) { var availableContracts = _musicContractsRepo.GetAll(); if (filter != null) { // I have left this as two separate linq queries for readability var distributionPartnerContracts = _distributionPartnerContractsRepo.GetAll() .Where(d => filter.DistributionParnterContractFilter(d)) .Select(d => d.Usage) .Distinct(); availableContracts = availableContracts .Where(m => m.Usages.Any(u => distributionPartnerContracts.Any(d => u.IsSameAs(d)))) .Where(m => filter.MusicContractFilter(m)); } return(availableContracts .OrderBy(x => x.Artist) .ThenByDescending(x => x.StartDate) .ToList()); }