title: One to Many mapping with an intermediate table
body: <p>I thought I had this one pegged by mapping the intermediary table as a HasMany and between intermediary and child as HasOne, however HasOne expects to share a key. (No Inverse option.:[ )</p>
  
  <p>Anyhow, the relational structure I have:</p>
  
  <blockquote>
    <p>Address (Child)<br>
    AddressId<br>
    ..Address Fields<br>
    <br>
    AddressCustomer (Intermediary)<br>
    AddressCustomerId<br>
    AddressId<br>
    CustomerId<br>
    <br>
    Customer (Parent)<br>
    CustomerId<br>
    ..Customer Fields</p>
  </blockquote>
  
  <p>Why I have this intermediary table instead of a normal 1-many? Because there will be other entities that will need to contain addresses. (I.e. Sites, etc.) They will have their own intermediary table so they can share the address table.</p>
  
  <p>Mappings I have so far:</p>
  
  <pre><code>    public class CustomerAddressMap : ClassMap&lt;CustomerAddress&gt;
  {
      public CustomerAddressMap()
      {
          Schema("dbo");
          Table("CustomerAddress");
          Id(x =&gt; x.CustomerAddressId);
          Map(x =&gt; x.FromDate)
              .Not.Nullable();
          Map(x =&gt; x.ToDate);
          HasOne(x =&gt; x.Address)
              .ForeignKey("AddressId")
              .Cascade.All();
      }
  
  }
  
  public class AddressMap : ClassMap&lt;Address&gt;
  {
      public AddressMap()
      {
          Schema("dbo");
          Table("Address");
          Id(x=&gt;x.AddressId);
          Map(x =&gt; x.AddressType);
      }
  }
  </code></pre>
  
  <p>With a null-able AddressId column in the CustomerAddress table, rows are inserted, however the AddressID from the Address row doesn't propagate back up to CustomerAddress. There is no Inverse option on HasOne so that seems to be a dead end. I cannot have the Address ID generated on CustomerAddress because this would result in duplicates once I add something like SiteAddress and have to do the same thing. That trick <em>may</em> work with GUIDs as keys, but I'm stuck with auto-increment Ints for the moment.</p>
  
  <p>Some other ideas I was noodling over was mapping a merge of CustomerAddress and Address but I don't believe that is supported with Fluent NHibby.</p>
  
  <p>I figure it's a problem domain that someone has successfully applied. Essentially I want a 1-Many relationship where the child table (not it's records) is shared between multiple parents. Any ideas?</p>