[Solved] Linq: help me to make this work


You should group all person skills by person id, and then select only those groups, which contain both given category and sub category:

unitOfWork.PersonSkillsRepository.GetAll()
          .GroupBy(p => p.PersonId)
          .Where(g => g.Any(p => p.IdCategory == ids.IdCategory) 
                   && g.Any(p => p.IdSubCategory == ids.IdSubCategory))
          .Select(g => g.Key)

For optimization, you can filter out skills which do not match any of given categories before grouping.

unitOfWork.PersonSkillsRepository.GetAll()
          .Where(p => p.IdCategory == ids.IdCategory 
                   || p.IdSubCategory == ids.IdSubCategory)
          .GroupBy(p => p.PersonId)
          .Where(g => g.Any(p => p.IdCategory == ids.IdCategory) 
                   && g.Any(p => p.IdSubCategory == ids.IdSubCategory))
          .Select(g => g.Key) 

5

solved Linq: help me to make this work