title: NHibernate one-to-many example. Is this a code smell?
body: <p>Recently I've found <a href="http://codebetter.com/iancooper/2009/01/07/introduction-to-nhibernate-part-3/" rel="nofollow">an example</a> on NHibernate's one-to-many relationship. The mapping goes like this:</p>
  
  <pre><code>&lt;class name="Company" table="Company"&gt;
      &lt;id name="Id" type="Int32" unsaved-value="0"&gt;
        &lt;generator class="identity"/&gt;
      &lt;/id&gt;
      &lt;version name="Version"/&gt;
      &lt;property name="Name"/&gt;
      &lt;set name="Customers" inverse="true" lazy="true" &gt;
        &lt;key column="Id"/&gt;
        &lt;one-to-many class="Customer"/&gt;
      &lt;/set&gt; 
  &lt;/class&gt;
  
  &lt;class name="Customer" table="Customer"&gt;
      &lt;id name="Id" type="Int32" unsaved-value="0"&gt;
        &lt;generator class="identity"/&gt;
      &lt;/id&gt;
      &lt;version name="Version"/&gt;
      &lt;property name="DateOfBirth"/&gt;
      &lt;property name="FirstName"/&gt;
      &lt;property name="Surname"/&gt;
      &lt;many-to-one name="Company" column="CompanyId" cascade="all-delete-orphan"/&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p>And this are the classes:</p>
  
  <pre><code>public class Company
  {
      private ISet&lt;Customer&gt; customers = new HashedSet&lt;Customer&gt;();
      public int Id { get; set; } 
      public string Name { get; set; }
      public int Version { get; set; }
      public ISet&lt;Customer&gt; Customers
      {
          get { return customers; }
          set { customers = value; }
      }
  }
  
  public class Customer
  {
      public Company Company { get; set; }
      public DateTime? DateOfBirth { get; set; }
      public string FirstName {get;set;}
      public int Id { get; set; }
      public string Surname {get;set;}
      public int Version { get; set; }
  }
  </code></pre>
  
  <p>What I don't like about this code is the inclusion of the parent inside the child, the whole Company object inside the Customer one. Won't this be a circular reference. I mean, when this graph loads won't I be able to do something like currentCustomer.Company.Customers.First().Company.Customers.Last() ... and so on? Or it doesn't work like that?</p>
  
  <p>Assuming the underlying table Customer had only a string column CompanyName, how could I map that? How would be the mapping if instead of a public Company Company I'd have a public string CompanyName in the Customer class?</p>