BennoDual
BennoDual

Reputation: 6289

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

Upvotes: 3

Views: 2519

Answers (1)

Pedro
Pedro

Reputation: 11904

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.

Upvotes: 3

Related Questions