title: Fluent Nhibernate mappings / Join
body: <p>In my code I have an three main entities:
  1. Company
  2. Staff
  3. Position</p>
  
  <blockquote>
    <p>A staff can have several positions in various companies.</p>
  </blockquote>
  
  <p>I want to retrieve all staff associated to a specific company. </p>
  
  <p>In code I would do something like:</p>
  
  <pre><code>public partial class Company
  {
      public virtual IEnumerable&lt;Position&gt; Positions { get; protected set; }
      public virtual IEnumerable&lt;Staff&gt; Staffs
      {
          get { return Positions.Select(x =&gt; x.Staff); }
      }
  }
  
  class CompanyMap : ClassMap&lt;Company&gt;
  {
      public CompanyMap()
      {
          Id(x =&gt; x.Id)
              .Column("CompanyId")
              .GeneratedBy.Identity();
          Map(x =&gt; x.Name)
              .Not.Nullable();
  
          HasMany(x =&gt; x.Positions)
              .KeyColumn("CompanyId")
              .AsBag();
      }
  }
  </code></pre>
  
  <p>Pb: In this solutionm I will load all positions associated to a company and then all staff associated to each position... In terms of performance it's not very good i guess...</p>
  
  <p>I'm pretty sure there is a better way to perform this join directly in the CompanyMap class.</p>
  
  <p>Could you help me to do that?</p>
  
  <p>Thank you,
  Sebastien</p>