title: Add multi-column unique constraint on foreign Key using fluent-nhibernate automapping
body: <p>I'm an NHibernate and fluent-nhibernate newbie. And I've got some problem with unique constraint and nhibernate mapping.</p>
  
  <p>I've got the following part of domain model.</p>
  
  <pre><code>public class Batch
  {
      public virtual int Id {get; set;}
      public virtual string Name {get; set;}
      public virtual IList&lt;BatchParameter&gt; BatchParameters {get; set;}
  }
  public class BatchParameter
  {
      public virtual int Id {get; set;}
      public virtual string Name {get; set;}
      public virtual Batch Batch {get; set;}
  }
  </code></pre>
  
  <p>I'm trying to use fluent-nhibernate to map it on the db (SQLServer) using automapping.
  I want to be set up my db in order to have :</p>
  
  <ul>
  <li><p>Primary Keys on the "Id"s properties</p></li>
  <li><p>a Foreign Key on the BatchParamets table</p></li>
  <li><p>a Unique Constraint on the Batch table on column Name</p></li>
  <li><p>a Unique Constraint on the BatchParameters table on columns Name and Batch_Id</p></li>
  </ul>
  
  <p>So I've written down this code:</p>
  
  <pre><code>public class BatchMapping : IAutoMappingOverride&lt;Batch&gt;
  {
      public void Override(FluentNHibernate.Automapping.AutoMapping&lt;Batch&gt; mapping)
      {
          mapping.Id( b =&gt; b.Id);
          mapping.HasMany&lt;BatchParameter&gt;(p =&gt; p.BatchParameters).Cascade.All().Inverse();
      }
  }
  
  public class BatchParameterMapping : IAutoMappingOverride&lt;BatchParameter&gt;
  {
      public void Override(FluentNHibernate.Automapping.AutoMapping&lt;BatchParameter&gt; mapping)
      {
          mapping.Id( b =&gt; b.Id);
          mapping.Map(b =&gt; b.Name).Unique();
          //mapping.Map(p =&gt; p.Name).UniqueKey("Batch_Parameter");
          //mapping.Map(p =&gt; p.Batch.Id).UniqueKey("Batch_Parameter");
      }
  }
  </code></pre>
  
  <p>No problems for the primary keys, the foreign key and the first Unique Constraint. A little bit of headache for the Unique Constraint.</p>
  
  <p>Can someone show me the straight way???</p>
  
  <p>Thanks!</p>