title: Fluent NHibernate mapping on multiple non-PK fields
body: <p>I have a situation similar to that described in <a href="https://stackoverflow.com/q/2192952/326110">Fluent NHibernate Mapping not on PK Field</a></p>
  
  <p>However, the relationship between my tables is described by multiple non-primary key columns.
  Imagine Chris Meek's situation but where a <code>Person</code> has a <code>JobType</code> and a <code>Code</code> that, together, <em>should</em> (sorry, it's a legacy database) uniquely describe a <code>Person</code></p>
  
  <pre><code>Person
  ------
  Id PK
  JobType
  Code
  Name
  
  Order
  -----
  Id PK
  Person_JobType
  Person_Code
  OrderDetails
  </code></pre>
  
  <p>Serhat Özgel's <a href="https://stackoverflow.com/a/2193013/326110">answer</a> describes using <code>PropertyRef</code>, but I can't find a way to do that individually for multiple columns. I've tried similar to</p>
  
  <pre><code>class PersonMap : ClassMap&lt;Person&gt;
  {
      public PersonMap()
      {
          HasMany(p =&gt; p.Order)
              .KeyColumns.Add("Person_JobType")
              .PropertyRef("JobType")
              .KeyColumns.Add("Person_Code")
              .PropertyRef("Code")
      }
  }
  </code></pre>
  
  <p>But this obviously doesn't work, since <code>KeyColumns.Add()</code> returns another <code>OneToManyPart</code> so <code>PropertyRef()</code> isn't being run against the individual column being added. The second <code>PropertyRef()</code> simply overwrites the first one, and I get the following error:</p>
  
  <pre><code>NHibernate.MappingException : collection foreign key mapping
  has wrong number of columns: MyApp.Person.Order type: Int32
  </code></pre>
  
  <p>I've looked at the various overloads of KeyColumns.Add(),</p>
  
  <pre><code>public TParent Add(string name)
  public TParent Add(params string[] names)
  public TParent Add(string columnName, Action&lt;ColumnPart&gt; customColumnMapping)
  public TParent Add(ColumnMapping column)
  </code></pre>
  
  <p>Specifically the last two, but couldn't find any way to set <code>PropertyRef</code> individually level for each column :(
  Is there a way to do that? Am I going about this the wrong way entirely?</p>