简体   繁体   中英

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.

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/

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM