我很难将一组结果作为List<KeyValuePair<string, string>>
以下是我当前的选择陈述
var fetchStudents = (from tg in dc.TEACHINGGROUPs
from sg in dc.STUGROUPs
.Where(sg => sg.GroupId == tg.GroupId)
.DefaultIfEmpty()
where sg.SetId == strSetId && tg.LecturerId == strLecturerID
from stu in dc.STUDENTRECORDs
.Where(stu => stu.StudentId == sg.StudentId)
.DefaultIfEmpty()
where stu.Name.StartsWith(name)
select new { studentName = stu.Name, studentID = stu.StudentId }).Distinct();
有没有办法可以将每个结果选为List<KeyValuePair<string, string>>
,以便我可以以正确的格式返回结果集?我有一种感觉,它正在盯着我的脸,但已经在它几个小时,我的大脑坏了..
答案 0 :(得分:2)
(from …
select new KeyValuePair<string, string>(stu.Name, stu.StudentId))
.Distinct().ToList()