title: Fluent NHibernate - Map 2 tables to one class
body: <p>I have two tables that I want to map to one class that will looks like:</p>
  
  <pre><code>CUSTOMER_INFO_CLASS.cs
  ----------------------
  Id (CUSTOMER table) 
  CustomerName (CUSTOMER table)
  CustomerTypeDesc (CUSTOMER_TYPE table)
  </code></pre>
  
  <p>I tried to do it with join, as follows: </p>
  
  <pre><code>Table("CUSTOMER");
  
  Id(x =&gt; x.ID).Length(10).Column("CustomerId");
  Map(x =&gt; x.CustomerName);
  
  Join("CUSTOMER_TYPE", m =&gt;
      {
      m.Optional();
      m.Map(x =&gt; x.CustomerTypeDesc);
      m.KeyColumn("CustomerType");
      });
  </code></pre>
  
  <p>The problem is that the field with whom I'm trying to link the two tables is not a primary key in any of them. (And by default the join done by the field that defined as ID)
  So I found that for the CUSTOMER_TYPE table I can define the field by “KeyColumn”.<br>
  How can I define that the related column in the CUSTOMER table will be CustomerTypeCode and not CustomerId? (if I can at all)</p>
  
  <p>At the end the sql query should looks like:</p>
  
  <pre><code>Select Id, CustomerName, CustomerAddress, CustomerTypeDesc
  From CUSTOMER t1
    Left join CUSTOMER_TYPE t2
      On t1.CustomerTypeCode = t2.CustomerType
  </code></pre>