NHibernate 中的身份和增量有什么区别?
What is the difference between identity and increment in NHibernate?
我在 Access 中使用我的数据库,我想按 ID 自动递增。
我应该使用哪一个?
Id(x => x.Id).GeneratedBy.Increment().Column("COLUMN_NAME");
或
Id(x => x.Id).GeneratedBy.Identity().Column("COLUMN_NAME");
来自 Hibernate Docs(Nhibernate 是 Java 项目的移植)
increment
generates identifiers of type long, short or int that are unique only
when no other process is inserting data into the same table. Do not
use in a cluster.
identity
supports identity columns in DB2, MySQL, MS SQL Server, Sybase and
HypersonicSQL. The returned identifier is of type long, short or int.
sequence
uses a sequence in DB2, PostgreSQL, Oracle, SAP DB, McKoi or a
generator in Interbase. The returned identifier is of type long, short
or int
native
selects identity, sequence or hilo depending upon the capabilities of the >underlying database.
所以增量应该用于小场景,增量是在内存中计算的。
Identity\Sequence\Native使用数据库的本机功能来计算增量。
由于您使用的是 Access,因此您可能处于第一种情况,但我建议您迁移到 MS SQL Server Express 以获得更好的性能、安全性、可用性和扩展性。它是免费的,迁移应该很轻松。
我在 Access 中使用我的数据库,我想按 ID 自动递增。
我应该使用哪一个?
Id(x => x.Id).GeneratedBy.Increment().Column("COLUMN_NAME");
或
Id(x => x.Id).GeneratedBy.Identity().Column("COLUMN_NAME");
来自 Hibernate Docs(Nhibernate 是 Java 项目的移植)
increment
generates identifiers of type long, short or int that are unique only when no other process is inserting data into the same table. Do not use in a cluster.
identity
supports identity columns in DB2, MySQL, MS SQL Server, Sybase and HypersonicSQL. The returned identifier is of type long, short or int.
sequence
uses a sequence in DB2, PostgreSQL, Oracle, SAP DB, McKoi or a generator in Interbase. The returned identifier is of type long, short or int
native
selects identity, sequence or hilo depending upon the capabilities of the >underlying database.
所以增量应该用于小场景,增量是在内存中计算的。
Identity\Sequence\Native使用数据库的本机功能来计算增量。
由于您使用的是 Access,因此您可能处于第一种情况,但我建议您迁移到 MS SQL Server Express 以获得更好的性能、安全性、可用性和扩展性。它是免费的,迁移应该很轻松。