title: Minimal and correct way to map one-to-many with NHibernate
body: <p>I am new to NHibernate and C#, so please be gentle!</p>
  
  <p>I have the following two NHibernate entities:</p>
  
  <pre><code>Employee
  {
      private long _id;
      private String _name;
      private String _empNumber;
      private IList&lt;Address&gt; _addresses;
  
      //Properties...
  }
  </code></pre>
  
  <p>and</p>
  
  <pre><code>Address
  {
      private long _id;
      private String _addrLine1;
      private String _addrLine2;
      private String _city;
      private String _country;
      private String _postalCode;
  
      //Properties
  }
  </code></pre>
  
  <p>and they have a <code>one-to-many</code> relationship from <code>Employee</code> to <code>Address</code> <em>(each
  employee can have multiple addresses in their record)</em>. Conveniently ignoring
  the fact that more than one employee may reside at the same address.</p>
  
  <p>I understand this from the perspective of objects in memory (the NHibernate
  entities).  What I am struggling with are the mapping files (and I am taking an
  easy example here).  This is what I have come up with so far:</p>
  
  <pre><code>// Intentionally left out XML and &lt;hibernate-mapping&gt; 
  // Mappings for class 'Employee'. --&gt;
  &lt;class name="Employee" table="Employees"&gt;
      &lt;id name="ID"&gt;
          &lt;generator class="native"&gt;
      &lt;/id&gt;
  
      &lt;property name="Name" /&gt;
      &lt;property name="EmpNumber" /&gt;
  
      &lt;bag name="Addresses"&gt;
          &lt;key column="AddressId" /&gt;
          &lt;one-to-many class="Address" /&gt;
      &lt;/bag&gt;
  &lt;/class&gt;
  </code></pre>
  
  <p>and</p>
  
  <pre><code>// Intentionally left out XML and &lt;hibernate-mapping&gt; .
  // Mappings for class 'Address'
  &lt;class name="Address" table="Addresses"&gt;
      &lt;id name="ID"&gt;
          &lt;generator class="native"&gt;
      &lt;/id&gt;
  
      // Intentionally left out name="Employee" 
      // as I don't have corresponding field in Address entity.
      &lt;many-to-one class="Employee" column="EmployeeID" cascade="all" /&gt;
  
      &lt;property name="AddrLine1" /&gt;
      &lt;property name="AddrLine2" /&gt;
      &lt;property name="City" /&gt;
      &lt;property name="Country" /&gt;
      &lt;property name="PostalCode" /&gt;
  &lt;/class&gt;
  </code></pre>
  
  <ol>
  <li>Is this correct?</li>
  <li>If not, it seems like what I am missing here is a field in the <code>Address</code>
  entity that is a reference to the corresponding <code>Employee</code> entity.  But if
  so, then I can't understand why this is required: I don't need to fetch an
  <code>Address</code> from an <code>Employee</code>, only the other way round...</li>
  </ol>