【问题标题】:Multiple Primary Keys in Nhibernate?Nhibernate中的多个主键?
【发布时间】:2011-11-23 17:10:46
【问题描述】:

在 NHibernate 中映射时如何分配多个主键?

    Id(x => x.TopicID); <<----Primary Key
        Map(x => x.Topic);   <<---Should Also be a Primary Key
        Map(x => x.Subtitle);
        Map(x => x.Description);
        Map(x => x.ImageURL);

    }

【问题讨论】:

  • Topic 不是对象,不是 ID? p.s.您确实应该标记一些已接受的答案 - 您已经提出了 12 个问题,但没有接受任何问题 - 这对您的声誉不利。
  • 您的意思是复合键还是——正如“也”这个词所暗示的——替代键?

标签: nhibernate orm mapping


【解决方案1】:

使用 CompositeID 方法:

CompositeId()
.KeyProperty(x => x.TopicId, "name")
.KeyReference(x => x.Topic, "anotherName");

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-15
    • 1970-01-01
    • 2011-09-26
    • 1970-01-01
    • 2014-11-17
    • 1970-01-01
    相关资源
    最近更新 更多