2011-05-22 83 views
0

我奋力一组结果返回到automplete插件作为List<KeyValuePair<string, string>>LINQ to SQL的多个表中选择的密钥值对

下面是我目前的select语句

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>>,以便我可以以正确的格式返回结果集?我有一种感觉,它正在凝视我的脸,但已经在它几个小时,我的大脑被打破了..

回答

2
(from … 
select new KeyValuePair<string, string>(stu.Name, stu.StudentId)) 
    .Distinct().ToList()