title: How do I populate the class list which has list of classes for each class item with MySQL data?
body: <p>This is one of the classes I have in C# : </p>
  
  <pre><code>public class Courses
      {
          [DataMember]
          public string SchoolName { get; set; }
          [DataMember]
          public string MajorName { get; set; }
          [DataMember]
          public List&lt;string&gt; Course { get; set; }
  
          public Courses()
          {
              Course = new List&lt;string&gt;();
          }
      }
  </code></pre>
  
  <p>For each Major, there is a list of classes.</p>
  
  <p>In my database, I have three tables for school, major and courses joined with foreign leys. A simple SQL table to read them would be for a given school :</p>
  
  <pre><code>SELECT 
  major.MajorName,
  course.CourseName 
  FROM school
  INNER JOIN major ON major.MajorID = course.MajorID  
  WHERE school.SchoolName = @SchoolName AND major.SchoolNameID = school.SchoolNameID GROUP BY major.MajorName;
  </code></pre>
  
  <p>So based on this, I expect the data as follows.
  (Multiple major names and each major with multiple courses)</p>
  
  <pre><code>MajorName   CourseName
  Science      SC101
  Science      SC102
  Science      SC500
  Math         MA100
  Math         MA200
  ENGLISH      EN450
  </code></pre>
  
  <p>What is the best way I could populate the class I derived at the beginning?
  My class definision inside database read query would be :</p>
  
  <pre><code>List&lt;Courses&gt; majorclasses = new List&lt;Courses&gt;() 
  </code></pre>
  
  <p>I could manual manage the data to populate the class by reading distinct majorNames and then populating each course for each majorName in a loop. </p>
  
  <pre><code>(pheudo code)
  List&lt;string&gt; distinctMajors = majorClasses.Disticnt("majorNames").ToList()
  foreach major in distinctMajors
  {
     course.Add(courseName)
  }
  </code></pre>
  
  <p>Any other better method to acheive this ?</p>