Nic
Nic

Reputation: 1089

Fluent nhibernate how to generate Unique id

I am sorry for simplest question but I want to now if is any way to generate id column on each table to be like 1,2,3,4,... n. Now I have following :

 Id(x => x.Id).GeneratedBy.Identity();

For each table this will generate Id from 1 to n , on each table will start again from one but I need Id column to be unique in all my database.To start from one and continue to N.How I can achieve this? Thanks a lot.

Upvotes: 0

Views: 1118

Answers (1)

Only a Curious Mind
Only a Curious Mind

Reputation: 2857

You have two ways:

1. Create a unique Sequence in your database and map like this:

  Id(x => x.Id).GeneratedBy.Native("YOURSEQUENCE_SEQ");

2. Use a NHibernate HiLo to control your ids (its the better approach) read more in this link:

http://www.philliphaydon.com/2010/10/using-hilo-with-fluentnhibernate/

Upvotes: 4

Related Questions