【问题标题】:How to create composite UNIQUE constraint in FluentNHibernate?如何在 FluentNHibernate 中创建复合 UNIQUE 约束?
【发布时间】:2016-02-08 19:20:31
【问题描述】:

我知道我可以Map(x => x.GroupName).WithUniqueConstraint() 获取单个属性。

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

【问题讨论】:

    标签: nhibernate fluent-nhibernate nhibernate-mapping


    【解决方案1】:

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

    Map(x => x.Something).UniqueKey("KeyName");
    Map(x => x.SomeOtherThing).UniqueKey("KeyName");
    

    【讨论】:

    • 这对我不起作用。键已创建,但它仅包含第一个字段。
    【解决方案2】:

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

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

    【讨论】:

      猜你喜欢
      • 2021-08-16
      • 2012-12-30
      • 1970-01-01
      • 2016-10-27
      • 2020-01-17
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多