title: NHibernate one way, one-to-many, mapping question
body: <p>I have a scenario in NHibernate where I have a one-to-many relationship between entities Employee and EmployeeStatus.</p>
  
  <p>Employee has properties eg: ID, Name and an IList of EmployeeStatus, whilst EmployeeStatus, for the purposes of this question, just has it's own ID and some free text.</p>
  
  <p>I don't need to hold a reference to Employee from EmployeeStatus, the management of status' will be done purely through the Employee entity - adding to the IList property. IE: I want to quite simply be able to do the following;</p>
  
  <pre><code>Employee e = new Employee();
  e.Name = "Tony";
  e.StatusList.Add( new EmployeeStatus("Status A") );
  e.StatusList.Add( new EmployeeStatus("Status B") );
  session.Save(e);
  </code></pre>
  
  <p>I've tried various methods, including creating a one way one-to-many mapping where inverse is false, cascade set to all-delete-orphan, which all looks like it should work, but it generates an exception about being unable to set the EmployeeId in EmployeeStatus. I'm led to believe that this is because NHibernate wants to do an insert with EmployeeId as NULL and then update it to the ID of the parent.</p>
  
  <p>I guess I'm missing something here, so quite simply - can anyone tell me what my mapping file should look like to achieve the above?</p>
  
  <p>Thanks in advance</p>
  
  <p>Tony</p>
  
  <p>-- edit: Heres a rough idea of the classes as requested --</p>
  
  <pre><code>public class Employee
  {
    private IList&lt;EmployeeStatus&gt; _statusList;
  
    public Employee()
    {
      _statusList = new List&lt;EmployeeStatus&gt;();
    }
  
    public virtual int Id{ get; set; }
  
    public virtual string Name{ get; set; }
  
    public virtual IList&lt;EmployeeStatus&gt; StatusList
    {
      get
      {
        return _statusList;
      }
    }
  }
  
  public class EmployeeStatus
  {
    public virtual int Id{ get; set; }
    public virtual string StatusText{ get; set; }
  
    public EmployeeStatus()
    {
    }
  
    public EmployeeStatus(string statusText)
    {
      StatusText = statusText;
    }
  }
  </code></pre>