title: How do I create a NHibernate Mapping file for a multi-value component that is a Unique set of columns?
body: <p>I'm using NHibernate and Fluent NHibernate to create a mapping file for a domain object (though I don't care if an answer uses fluent NHibernate or xml hbm syntax).  And I'm having trouble with figuring out how I specify that a set of columns representing a component within the domain object is unique.</p>
  
  <p>Here's the domain object:</p>
  
  <pre><code>public class SpaceLocation
  {
          public SpaceCoordinate Coordinates { get; set; }
          public SpaceObject AtLocation { get; set; }
  }
  </code></pre>
  
  <p>and here is the component I'm having trouble with:</p>
  
  <pre><code>public struct SpaceCoordinate
  {
          public int x { get; set; }
          public int y { get; set; }
          public int z { get; set; }
  }
  </code></pre>
  
  <p>Don't worry about <code>SpaceObject AtLocation</code> for the purposes of this quesiton.</p>
  
  <p>So I know how to make a component out of SpaceCoordinate, but I want to make it so that there cannot be duplicate inserts of the same set of Coordinates.  In order to do this, I want to make the component as a whole unique.</p>
  
  <p>To give you a sense of the direction I'm trying to go, I'll show you what I have for the mapping class:</p>
  
  <pre><code>public class SpaceLocationMap : ClassMapWithGenerator&lt;SpaceLocation&gt;
      {
          public SpaceLocationMap()
          {
  
              Component&lt;SpaceCoordinate&gt;(x =&gt; x.Coordinates, m =&gt; 
              {
                  m.Map(x =&gt; x.x);
                  m.Map(x =&gt; x.y);
                  m.Map(x =&gt; x.z);
              });
          }
      }
  </code></pre>
  
  <p>The problem with this Fluent NHibernate mapping is that it does not apply the unique constraint to the SpaceCoordinate's values collectively.  Mind you I'm not trying to set each as unique individually, that would be too restrictive.</p>
  
  <p>So how would you map with this with a hbm or fluent map file?</p>
  
  <p>Any help would be greatly appreciated, Thanks for reading!!</p>