C# Linq到SQL多表选择为键值对
我正在努力将一组结果作为C# Linq到SQL多表选择为键值对,c#,linq,linq-to-sql,C#,Linq,Linq To Sql,我正在努力将一组结果作为列表返回给一个autocomplete插件 下面是我当前的select语句 var fetchStudents = (from tg in dc.TEACHINGGROUPs from sg in dc.STUGROUPs .Where(sg => sg.GroupId == tg.GroupId) .DefaultIfEmpty() where sg.SetId == strSetId &&
列表返回给一个autocomplete插件
下面是我当前的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();
是否有一种方法可以选择每个结果作为列表
,以便以正确的格式返回结果集?我有一种感觉,它正盯着我的脸,但我已经盯着它看了好几个小时,我的大脑已经崩溃了…
(from …
select new KeyValuePair<string, string>(stu.Name, stu.StudentId))
.Distinct().ToList()
选择新的KeyValuePair(stu.Name,stu.StudentId))
.Distinct().ToList()