简体   繁体   中英

NHibernate and MS SQL function NEWSEQUENTIALID() to generate an ordered GUID

How can I configure NHibernate 3.3.1 (or some other version) to allow Microsoft SQL 2008 R2 to generate the primary key value (guid that is ordered) for a table with data type uniqueidentifier and default constraint NEWSEQUENTIALID()?

My testing has shown that I can setup the Id (PK) mapping as GeneratedBy.Guid.Native() but this will call select newid() and will not use the function NEWSEQUENTIALID().

I could generate the ordered guid client side with Id mapping, GeneratedBy.GuidComb() but I am concerned about multiple threads within the same process generating the same GUID.

My application requires database replication across active/active data centers and I would like to use ordered guids generated at the MS SQL servers (several active data centers) as primary keys.

I see this article,

Nhibernate Identity mapping when using "newsequentialid" in DB ,

but it seems to be missing the point with the answer that shows how to setup NHibernate to use an NHibernate generated GUId.

Any help will be appreciated.

By default I believe nhibernate uses a guid.comb strategy to generate guids which should be ordered. They aren't as obvious as when generated by NEWSEQUENTIALID() but should still be ordered.

Check out the following article on this:

http://nhibernate.info/blog/2009/05/21/using-the-guid-comb-identifier-strategy.html

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