2017-06-01 113 views
0

您好我正在使用下面的查詢來選擇studentId和Score1從table1現在我想選擇用戶,我從table2選擇他們的ID,我怎麼可以選擇它與ID? 我可以選擇用戶與此查詢
from v in dc.tbl_Students select v但我想選擇一些用戶,我有他們的ID。從linq中選擇一些ID

var qBestMan = (from T in (((from tbl_ActPoints in dc.tbl_ActPoints 
             select new 
             { 
              StudentId = (int?)tbl_ActPoints.StudentId, 
              Score = (int?)tbl_ActPoints.Score 
             }).Concat(
       from tbl_EvaPoints in dc.tbl_EvaPoints 
       select new 
       { 
        StudentId = (int?)tbl_EvaPoints.StudentId, 
        Score = (int?)tbl_EvaPoints.Score 
       }))) 
         group T by new 
         { 
          T.StudentId 
         } into g 
         orderby g.Sum(p => p.Score) descending 
         select new 
         { 
          g.Key.StudentId, 
          HighScoreUser = g.Sum(p => p.Score) 
         }).ToArray(); 

回答

0

嘗試這樣:

 //qBestMan must be a List, or a IEnumarable and not a Array. Remove the .ToArray() at the end, or substitute it by .ToList() 
     var Result = from users in dc.tbl_Students 
         join bestMen in qBestMan on bestMen.StudentId equals users.userid        
         select new 
         { 
          //fields that you want 
          example = users.example, 
          other = bestMen.other 
         };