title: Use Linq to return multiple values using DTO
body: <pre><code>//This is student model
  namespace StudentApp.Models
  {
      public class Student
      {
          [Key]
          public int studentId { get; set; }
          public List&lt;AssignedSupervisor&gt; assigned_supervisorId { get; set; }
      }
      public class AssignedSupervisor
      {
          [Key]
          public int supervisorId { get; set; }
      }
  }
  </code></pre>
  
  <p>Based on the Student Model, entity framework has created the below db</p>
  
  <pre><code>//Here is the sample db structure
  //Table Students
  studentId
  ---------
      1
      2
  //Table Supervisors
  supervisorId | studentId
  ------------   ---------
       101           1
       102           1
       105           2
  </code></pre>
  
  <p>studentId is a foreign key in Supervisor Table. Students can have one or more supervisors assigned. 
  Required output should be similar to the below example:</p>
  
  <pre><code>{
    "studentId": "1",
    "supervisorId": [101,102]
  },
  {
    "studentId": "2",
    "supervisorId": [105]
  }
  </code></pre>
  
  <p>Below is the DTO</p>
  
  <pre><code>//This is student DTO
  namespace StudentApp.DTOs
  {
      public class StudentDTO
      {
          public int studentId { get; set; }
          public List&lt;AssignedSupervisor&gt; assigned_supervisorId { get; set; }
      }
  }
  </code></pre>
  
  <p>In my controller</p>
  
  <pre><code>namespace ContractingApp.Controllers
  {
      //first way I'm doing which returns ugly JSON.
      public List&lt;StudentDTO&gt; GetStudents()
      {
          return db.Students.Select(s =&gt; new StudentDTO()
          {
              studentId = s.studentId,
              //Not sure how to use the select statement with it
              assigned_supervisorId = s.Supervisors.Where(
                  u =&gt; u.studentId == s.studentId
                  ).ToList()
          }).ToList();
      }
  
      //Another way I have tried after the suggestions by @darth_phoenixx I'm trying which doesn't return correct correct format either.
      //It returns 3 JSON objects - one with each supervisor ID.
      public List&lt;dynamic&gt; GetStudents()
      {
          var students = (from t1 in db.Students
                          join t2 in db.Supervisors on t1.studentId equals t2.studentId
                          select new
                          {
                             t1.studentId,
                             t2.supervisorId
                          });
          return students.ToList&lt;dynamic&gt;();
      }
  }
  </code></pre>
  
  <p>Any article or direction to solve will be helpful.</p>