Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create composite UNIQUE constraint in FluentNHibernate?

Tags:

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

like image 875
Nathan Avatar asked Jan 20 '09 23:01

Nathan


2 Answers

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"); 
like image 138
Mark Rogers Avatar answered Oct 07 '22 20:10

Mark Rogers


Use SetAttribute in your mapping file like so:

Map(x => x.Something).SetAttribute("unique-key", "someKey"); Map(x => x.SomeOtherThing).SetAttribute("unique-key", "someKey"); 
like image 36
mookid8000 Avatar answered Oct 07 '22 19:10

mookid8000