Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate - Identity Column

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

like image 430
BennoDual Avatar asked Jan 30 '26 10:01

BennoDual


1 Answers

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.

like image 160
Pedro Avatar answered Feb 01 '26 02:02

Pedro



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!