title: How to save class with master/detail
body: <p>This is my class Record which can be master/detail/details
     Records of teachers and their students</p>
  
  <pre><code>class Record
  {
  
      public string RecorNo { get; set; }
  
      private List&lt;Teacher&gt; _Student = new List&lt;Teacher&gt;();
  
      public List&lt;Teacher&gt; Teacher
      {
  
          get { return _Teacher; }
          set { _Teacher=value; }
  
      }
      }
  
  
  class Teacher
  {
      private string _TeacherName;
  
      public Teacher(string teachername)
      {
          _TeacherName = teachername;
      }
  
      public string TeacherName
      {
          get { return _TeacherName; }
          set { _TeacherName = value; }
      }
  
      private List&lt;Students&gt; _students = new List&lt;Students&gt;();
  
      public List&lt;Students&gt; Students
      {
          get { return _students;}
          set { _students = value;}
  
      }
  
  
  }
  
  
  class Details
  {
  
  
      private string _studentname;
  
      public Details(string studentsname)
      {
  
          _studentsname = studentsname;
  
      }
  </code></pre>
  
  <p>I have bind the Teacher/Student in 2 datagridview like so:</p>
  
  <pre><code>TeacherBindingSource.DataSource = record.Teacher;
  StudentBindingSourcce.DataSource = TeacherBindingSource;
  StudentBindingSourcce.DataMember = "Student";
  
  dataGridView1.DataSource =TeacherBindingSource;
  dataGridView2.DataSource =  StudentBindingSourcce;
  </code></pre>
  
  <p>Now Im lost how to save this record.<br>
  How can I save this to the database?
  I want to have a.</p>
  
  <pre><code>           record.Save(); method that will save the whole object.
  </code></pre>
  
  <p>I can iterate through the list and insert it one by one but the record may be
  existing already in the database so i had to know which record is added, updated or deleted?</p>
  
  <p>Also how to make a method that will fill the teacher/student list like:</p>
  
  <pre><code>           records.LoadTeachers();
             records.Teacher("Smith").LoadStudents();
  </code></pre>