NHibernate - 身份列

发布于 2024-09-30 20:53:53 字数 622 浏览 0 评论 0原文

我已经声明了 NHibernate 的以下映射:

<class name="Sales" table="Sales" lazy="false"  >
    <id name="Id" column="Id" type="Guid">      
                    <generator class="assigned"/>
    </id>
  <version name="ObjectVersion" column="ObjectVersion"/>
    <property name="Number" column="Subject" type="String" length="255"  />
    <property name="Text" column="Body" type="String" length="50" not-null="true"  />
</class>

我现在应该添加一个名为 Key 的附加列,它被定义为自动增量列。有人可以告诉我如何声明此专栏吗?该列不必是主键 - 我只需要一个附加列,其中包含一个对每个记录进行计数的整数。

感谢您的帮助。

最好的问候,托马斯

I have declareted the fallowing Mapping for NHibernate:

<class name="Sales" table="Sales" lazy="false"  >
    <id name="Id" column="Id" type="Guid">      
                    <generator class="assigned"/>
    </id>
  <version name="ObjectVersion" column="ObjectVersion"/>
    <property name="Number" column="Subject" type="String" length="255"  />
    <property name="Text" column="Body" type="String" length="50" not-null="true"  />
</class>

I should now add a additional Column called Key which is defined as an AutoIncrement-Column. Can someone give me a tip how I have to declare this column? This Column has not to be the primary-key - i need only a additional column which has a integer which count up for each record.

Thanks for your help.

Best Regards, Thomas

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

痞味浪人 2024-10-07 20:53:53

您使用的是 SQL Server 吗?如果是,那么只需创建一个 Identity 列 ALTER TABLE Sales ADD Key INTEGER Identity(1,1) 然后将其映射为普通属性。它不会是主键,但会自动递增。

Are you using SQL Server? If yes, then just create an Identity column ALTER TABLE Sales ADD Key INTEGER Identity(1,1) Then map it as a normal property. It will not be the primary key but it will auto-increment.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文