我有一个 LINQ to Entities 查询,我只需要返回“ProgramYears”的唯一实例,这样我就可以在我的视图中遍历它们。我不知道如何改变它,这样我就不会得到重复。
var data = from SurveyProgramModel in surveyProgramRepository.Get()
where SurveyProgramModel.ProgramYear == ProgramYear
group SurveyProgramModel by SurveyProgramModel.ProgramTypeId into programTypeGroup
select new ProgramTypeViewModel()
{
ProgramTypeIds = programTypeGroup.Key,
ProgramIds = programTypeGroup.Select(r => r.ProgramId),
ProgramYears = programTypeGroup.Select(r => r.ProgramYear),
ProgramTitles = programTypeGroup.Select(r => r.ProgramTitle),
ProgramTypes = programTypeGroup.Select(r => r.ProgramType.ProgramType).Distinct(),
};