NHibernate mapping by code - composite unique index

1.7k views Asked by At

How do I create a composite UNIQUE constaint on 3 properties of a class? It needs to allow NULL as a legitimate value.

1

There are 1 answers

0
h.alex On BEST ANSWER

This should be one of the ways to go about it..

        mapper.Class<MyClass>(ca =>
            {
                ca.Property(x => x.Property1, map => map.UniqueKey("UQ_ComposedUniqueKey"));
                ca.ManyToOne(x => x.FKField1, map => { map.UniqueKey("UQ_ComposedUniqueKey"); map.NotNullable(false); });
            });

You can combine many properties or FKs in a single unique key.