26

I know that I can Map(x => x.GroupName).WithUniqueConstraint() for a single property.

But how do create a composite unique constraint in fluent nHibernate (where the unique constraint operates on the combination of two columns)?

BartoszKP
  • 34,786
  • 15
  • 102
  • 130
Nathan
  • 10,593
  • 10
  • 63
  • 87

2 Answers2

34

In the latest version that I have used, it isUniqueKey("KeyName")that does this.

Map(x => x.Something).UniqueKey("KeyName");
Map(x => x.SomeOtherThing).UniqueKey("KeyName");
Mark Rogers
  • 96,497
  • 18
  • 85
  • 138
8

Use SetAttribute in your mapping file like so:

Map(x => x.Something).SetAttribute("unique-key", "someKey");
Map(x => x.SomeOtherThing).SetAttribute("unique-key", "someKey");
mookid8000
  • 18,258
  • 2
  • 39
  • 63