title: Help trying to link two tables that share a common database column in nHibernate using HasOne
body: <p>I'm using nHibernate on a webpage for viewing items from an already existing database.  I'm having trouble linking two tables together.  The two tables share a common column name that I need to cross reference.  Granted, I would have designed the tables a little differently to just use a reference ID better but being this is a legacy database, I really need to figure out how to configure my Map to work on the existing schema.</p>
  
  <p>I’m trying to use a HasOne relationship between two tables (I can also see how this could also fit into the ManyToOne) but I just can't seem to get anything to work with the right results...Having exhausted my Google cache I'm now hoping someone might be able to offer some quick insights to what I'm doing wrong.</p>
  
  <p>The first table is called 'Report' which wants to load an object from another table called 'OperatingSystem'; Both share the common field ‘Report_Number’</p>
  
  <p>The Model classes look like this:</p>
  
  <pre><code>  public class ReportModel
    {
      public virtual int Report_Number { get; set; }
      public virtual OperatingSystemsModel OperatingSystem { get; set; }
    }
    public class OperatingSystemsModel
    {
      public virtual string OS_Name { get; set; }
      public virtual int Report_Number { get; set; }
    }
  </code></pre>
  
  <p>*The important difference from the normal situation is that the two records are indexed via the Report_Number rather than the Report having an index into the Operating system.</p>
  
  <p>The table mappings look like this:</p>
  
  <pre><code>public ReportMap()
  {
    Table("pcd_PROBLEM40");
    Id(x =&gt; x.Report_Number).Column("Report_Number").GeneratedBy.Native();
    HasOne(x =&gt; x.OperatingSystem).PropertyRef(x =&gt; x.Report_Number).ForeignKey("Report_Number");
  }
  public OperatingSystemsMap()
  {
    Table("pcd_os_names");
    Id(x =&gt; x.Report_Number).Column("Report_Number").GeneratedBy.Native();
    Map(x =&gt; x.OS_Name);
  }
  </code></pre>
  
  <p>The goal being that the ReportModel’s OperatingSystem object will get populated correctly from the shared Report_number feild.</p>
  
  <p>I’ve tried a variety of combinations of HasOne() with PropertyRef() and ForeignKey() but can’t seem to get one that works.
  I keep getting the following exception when I try to get a report.</p>
  
  <p>{"Unknown column 'operatings2_.Report_Number' in 'field list'"}</p>
  
  <pre><code>public static ReportModel GetReport(int i_iReportNumber)
  {
    ICriteria criteria = Session.CreateCriteria(typeof(ReportModel));
    criteria.Add(Restrictions.Eq("Report_Number", i_iReportNumber));
    return criteria.UniqueResult&lt;ReportModel&gt;();
  }
  </code></pre>
  
  <p>Any insights would be much, much appreciated!</p>