How to create an NHibernate mapping file for a multi-valued component that is a unique set of columns?

I use NHibernate and Fluent NHibernate to create a mapping file for a domain object (although I don't care if the response uses free NHibernate or xml hbm syntax). And I'm having trouble figuring out how I indicate that the set of columns representing the component in the domain object is unique.

Here's the domain object:

public class SpaceLocation
{
        public SpaceCoordinate Coordinates { get; set; }
        public SpaceObject AtLocation { get; set; }
}

and here is the component I'm having problems with:

public struct SpaceCoordinate
{
        public int x { get; set; }
        public int y { get; set; }
        public int z { get; set; }
}

Do not worry about SpaceObject AtLocationfor the purposes of this quesiton.

So, I know how to make a component from SpaceCoordinate, but I want to make sure that there are no duplicate inserts of the same set of coordinates. To do this, I want to make the component unique.

, , , :

public class SpaceLocationMap : ClassMapWithGenerator<SpaceLocation>
    {
        public SpaceLocationMap()
        {

            Component<SpaceCoordinate>(x => x.Coordinates, m => 
            {
                m.Map(x => x.x);
                m.Map(x => x.y);
                m.Map(x => x.z);
            });
        }
    }

Fluent NHibernate , SpaceCoordinate. , , .

, hbm ?

, !

+2
2

m4bwav hbm; Fluent NHibernate , . , Unique .

Component<SpaceCoordinate>(x => x.Coordinates, m => 
{
  m.Map(x => x.x);
  m.Map(x => x.y);
  m.Map(x => x.z);
}).Unique();

, Fluent NHibernate. - , SetAttribute, .

Component<SpaceCoordinate>(x => x.Coordinates, m => 
{
  m.Map(x => x.x);
  m.Map(x => x.y);
  m.Map(x => x.z);
}).SetAttribute("unique", "true");
+2

, :

<class name="SpaceLocation" table="SpaceLocation">
    <property name="AtLocation" type="SpaceObject"/>
    <component name="Coordinates" class="SpaceCoordinate" unique="true">
        <property name="x"/>
        <property name="y"/>
        <property name="z"/>
    </component>
</class>

. , nhibernate?

0

All Articles