Search code examples
sqlsql-serverlinqlinq-to-sqlsql-query-store

select some ids from sql in linq


hi I'm using the query below to select studentId and Score from table1 now i want select users that i selected their ids from table2, how i can select it with ids? i can select users with this query
from v in dc.tbl_Students select v but i want select some users that i have their 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();

Solution

  • Try something like this:

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