【问题标题】:select some ids from sql in linq从 linq 中的 sql 中选择一些 id
【发布时间】:2017-06-01 20:15:00
【问题描述】:

嗨,我正在使用下面的查询从 table1 中选择 studentId 和 Score,现在我想选择我从 table2 中选择他们的 id 的用户,我如何使用 id 选择它? 我可以使用此查询选择用户
from v in dc.tbl_Students select v 但我想选择一些我有他们的 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();

【问题讨论】:

    标签: sql sql-server linq linq-to-sql sql-query-store


    【解决方案1】:

    试试这样的:

            //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
                            };
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2010-10-03
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2015-09-09
      • 2019-05-04
      • 1970-01-01
      相关资源
      最近更新 更多