Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/csharp/261.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C# Linq到SQL多表选择为键值对_C#_Linq_Linq To Sql - Fatal编程技术网

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()