简体   繁体   English

流利的NHibernate如何生成唯一ID

[英]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. 对于最简单的问题,我感到抱歉,但是我现在想知道是否可以通过某种方式在每个表上生成id列,使其像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? 对于每个表,它将从1到n生成Id,在每个表上将再次从1开始,但我需要Id列在我的所有数据库中都是唯一的。要从1开始并继续到N,如何实现呢? Thanks a lot. 非常感谢。

You have two ways: 您有两种方法:

1. Create a unique Sequence in your database and map like this: 1.在数据库中创建一个唯一的Sequence并按以下方式进行映射:

  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: 2.使用NHibernate HiLo控制您的ID(这是更好的方法),请阅读以下链接中的更多内容:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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