How to create composite UNIQUE constraint in FluentNHibernate?

天涯浪子 提交于 2019-12-18 05:28:33

问题


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


回答1:


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



回答2:


Use SetAttribute in your mapping file like so:

Map(x => x.Something).SetAttribute("unique-key", "someKey");
Map(x => x.SomeOtherThing).SetAttribute("unique-key", "someKey");


来源:https://stackoverflow.com/questions/463499/how-to-create-composite-unique-constraint-in-fluentnhibernate

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!