title: Bind data from SQL to the objects with have the reference to another class
body: <p>I have the following class:</p>
  
  <pre><code>    public class Student : StudentInfo
      {
          public School School { get; set; }
      }
  
      public abstract class School
      {
          public string SchoolName { get; set; }
  
          public string SchoolAddress { get; set; }
      }
  
      public abstract class StudentInfo
      {
          public string StudentName { get; set; }
  
          public string StudentAge { get; set; }
  
          public string StudentGender { get; set; }
  
          public Relationship StudentRelationship { get; set; }
      }
  
      public abstract class Relationship
      {
          public string StudentMotherName { get; set; }
  
          public string StudentFatherName { get; set; }
      }
  </code></pre>
  
  <p>And I have the following SQL query that return all necessary data and ready to be bind into the classes above, I am doing it like the following:</p>
  
  <pre><code>    private List&lt;Student&gt; StudentList()
      {
          var students = new List&lt;Student&gt;();
  
          using (var conn = new SqlConnection(ConfigurationManager.ConnectionStrings["Connection"].ConnectionString))
          {
              conn.Open();
  
              string query = "SELECT a.[StudentName], a.[StudentAge], a.[StudentGender], a.[StudentMotherName], a.[StudentFatherName], b.[SchoolName], b.[SchoolAddress]
  FROM [Student] a WITH (NOLOCK) INNER JOIN [School] b WITH (NOLOCK) ON a.[StudentID] = b.[StudentID]";
  
              using (var cmd = new SqlCommand(query, conn))
              {
                  using (var reader = cmd.ExecuteReader())
                  {
                      while (reader.Read())
                      {
                          students.Add
                          (
                              new Student
                              {
                                  StudentName = reader["StudentName"].ToString(),
                                  StudentAge = reader["StudentAge"].ToString(),
                                  StudentGender = reader["StudentGender"].ToString()
                              }
                          );
                      }
                  }
              }
          }
  
          return students;
      }
  </code></pre>
  
  <p>I am confused on how to bind the objects into <strong>StudentInfo</strong> and <strong>School</strong> and <strong>Relationship</strong> class, since I am just instantiate the Student class.</p>
  
  <p>Any help would be much appreciated.</p>
  
  <p>Thanks</p>