NHibernate - 身份列
我已经声明了 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您使用的是 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.