views:

671

answers:

2

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)?

+4  A: 

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
+4  A: 

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
this doesn't work for me. The key is created, but it only includes the first field.
sydneyos