2

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

Andrew Shepherd
  • 44,254
  • 30
  • 139
  • 205
Tomas Grosup
  • 6,396
  • 3
  • 30
  • 44

1 Answers1

4

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.

h.alex
  • 902
  • 1
  • 8
  • 31