title: Fluent NHibernate - HasMany on composite key
body: <p>How do you create a HasMany relation on a legacy database which has no Foreign Key and columns differently named? I know how to create a one-to-one relation on HeaderVersion using References, but don't know how to create HasMany from Header 1 to * HeaderVersion.
  Join condition should be:</p>
  
  <pre><code>Header.Id1 = HeaderVersion.PId1 AND Header.Id2 = HeaderVersion.PId2
  </code></pre>
  
  <p><a href="https://i.stack.imgur.com/Mpxat.png" rel="nofollow noreferrer"><img src="https://i.stack.imgur.com/Mpxat.png" alt="Model"></a>
  </p>
  
  <p>Domain:</p>
  
  <pre><code>public class Header {
      public virtual int Id1 { get; set; }
      public virtual int Id2 { get; set; }
      public virtual string Something { get; set; }
  }
  
  public class HeaderVersion {
      public virtual int PId1 { get; set; }
      public virtual int PId2 { get; set; }
      public virtual int Version { get; set; }
      public virtual string SomethingFoo { get; set; }
  }
  </code></pre>
  
  <p>Map:</p>
  
  <pre><code> public HeaderMap() {
          Table("Header");
          LazyLoad();
          CompositeId().KeyProperty(x =&gt; x.Id1, "Id1")
                       .KeyProperty(x =&gt; x.Id2, "Id2");
          Map(x =&gt; x.Something).Column("Something");
   }
  
   public HeaderVersionMap() {
          Table("HeaderVersion");
          LazyLoad();
          CompositeId().KeyProperty(x =&gt; x.PId1, "PId1")
                       .KeyProperty(x =&gt; x.PId2, "PId2")
                       .KeyProperty(x =&gt; x.Version, "Version");
          Map(x =&gt; x.SomethingFoo).Column("SomethingFoo");
   }
  </code></pre>