2011-05-22 80 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()