title: Best practice for Handling NHibernate parent-child collections
body: <p>So in a typical model where you have a parent that can have many children and a child that can have only one parent, how do you manage the adding of children.  I have been using this approach;</p>
  
  <pre><code>public class Parent
  {
      public Parent()
      {
          Children = new List&lt;Child&gt;();
      }
  
      public IList&lt;Child&gt; Children
      {
          get;
          private set;
      }
  }
  
  public class Child
  {
      public Parent Parent
      {
          get;
          set;
      }
  }
  
  var child = new Child();
  var parent = new Parent();
  parent.Children.Add(child);
  child.Parent = parent;
  </code></pre>
  
  <p>Problem is that everywhere i want to add a new child i've got to remember to add a reference to both the child and parent and its a bit of a pain.  I could just add an AddChild method to the parent class and make that responsible for adding children - the problem now is that there is 2 ways to add a child, through the Children property and the method. So is this a better solution?</p>
  
  <pre><code>public class Parent
  {
      public Parent()
      {
          children = new List&lt;Child&gt;();
      }
  
      private IList&lt;Child&gt; children
      {
          get;
          private set;
      }
  
      public IEnumerable&lt;Child&gt; Children
      {
          get
          {
              return children;
          }
      }
  
      public void AddChild(Child child)
      {
          children.Add(child);
          child.Parent = this;
      }
  }
  </code></pre>
  
  <p>Are there any guidences for best practices on this, and what do you do?</p>