25

我知道我可以Map(x => x.GroupName).WithUniqueConstraint()为一个单一的财产。

但是如何在 fluent nHibernate 中创建复合唯一约束(其中唯一约束对两列的组合进行操作)?

4

2 回答 2

33

在我使用的最新版本中,就是UniqueKey("KeyName")这样做的。

Map(x => x.Something).UniqueKey("KeyName");
Map(x => x.SomeOtherThing).UniqueKey("KeyName");
于 2009-01-26T19:09:12.033 回答
8

SetAttribute在您的映射文件中使用,如下所示:

Map(x => x.Something).SetAttribute("unique-key", "someKey");
Map(x => x.SomeOtherThing).SetAttribute("unique-key", "someKey");
于 2009-01-26T18:58:51.727 回答