title: fluent nhibernate HasOne WithForeignKey not working
body: <p>Whenever I load a Task class, the Document property is always null, despite there being data in the db.</p>
  
  <p>Task class:</p>
  
  <pre><code>public class Task
  {
      public virtual Document Document { get; set; }
  </code></pre>
  
  <p>Task Mapping override for AutoPersistenceModel:</p>
  
  <pre><code>public void Override(AutoMap&lt;Task&gt; mapping)
  {
      mapping.HasOne(x =&gt; x.Document)
          .WithForeignKey("Task_Id");
  </code></pre>
  
  <p>As you can see form what NHProf says is being run, the join condition is wrong, the WithForeignKey doesnt seem to take effect. In fact, i can write any string in the above code and it makes no difference.</p>
  
  <pre><code>FROM   [Task] this_
      left outer join [Document] document2_
      on this_.Id = document2_.Id
  </code></pre>
  
  <p>It should be:</p>
  
  <pre><code>FROM   [Task] this_
      left outer join [Document] document2_
      on this_.Id = document2_.Task_Id
  </code></pre>
  
  <p>If i hack the data in the db so that the ids match, then data is loaded, but obviously this is incorrect - but at least it proves it loads data.</p>
  
  <p>Edit: rummaging in the fluent nhib source to find the XML produces this:</p>
  
  <pre><code>&lt;one-to-one foreign-key="Task_Id" cascade="all" name="Document" class="MyProject.Document, MyProject, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null" /&gt; 
  </code></pre>
  
  <p>Edit: heres the schema:</p>
  
  <pre><code>CREATE TABLE [dbo].[Document](
  [Id] [int] IDENTITY(1,1) NOT NULL,
  [Task_Id] [int] NOT NULL,
  
  CREATE TABLE [dbo].[Task](
  [Id] [int] IDENTITY(1,1) NOT NULL,
  </code></pre>
  
  <p>Anyone got any ideas?</p>
  
  <p>Thanks</p>
  
  <p>Andrew</p>