Search code examples
nhibernatefluent-nhibernatenhibernate-mapping

How to create composite UNIQUE constraint in FluentNHibernate?


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


Solution

  • 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");