NHibernate增量列,它不是';t id

NHibernate增量列,它不是';t id,nhibernate,auto-increment,Nhibernate,Auto Increment,我希望db为我自动增加一个EmployeeId。这将是一个业务id,与db id(由hilo生成)不同。我找到了一个看起来像的,但在实现它时遇到了问题 我不知道我得到的异常是因为映射不正确,SQLite无法处理它,还是其他原因。我还想知道是否有人对此有不同的解决方案 干杯, 浆果 映射 <class name="Resource" table="Resources" ...> <id name="Id" type="System.Int32" unsaved-value="0

我希望db为我自动增加一个EmployeeId。这将是一个业务id,与db id(由hilo生成)不同。我找到了一个看起来像的,但在实现它时遇到了问题

我不知道我得到的异常是因为映射不正确,SQLite无法处理它,还是其他原因。我还想知道是否有人对此有不同的解决方案

干杯,
浆果

映射

<class name="Resource" table="Resources" ...>

<id name="Id" type="System.Int32" unsaved-value="0">
  <column name="ResourceId" />
  <generator class="hilo" />
</id>
...
  <component name="EmployeeNumber" unique="true">
    <property name="StorageValue" generated="always" insert="false">
      <column name="EmployeeNumber" />
    </property>
  </component>
  ...
 </class>

 <database-object>
<create>
  ALTER TABLE Entity DROP COLUMN EmployeeNumber
  ALTER TABLE Entity ADD EmployeeNumber INT IDENTITY
</create>
<drop>
  ALTER TABLE Entity DROP COLUMN EmployeeNumber
</drop>
</database-object>

在ALTERTABLE SQLite语句的流程图中,我找不到DROP子句。只能添加和重命名列。因此,您可以将EmployeeNumber重命名为EmployeeNumber_old,而不是将其删除。您还可以删除并重新创建整个表(但如果这是一个包含生产数据的持久性SQLite DB,我建议不要这样做)

ALTER TABLE Entity DROP COLUMN EmployeeNumber
  ALTER TABLE Entity ADD EmployeeNumber INT IDENTITY

ALTER TABLE Entity DROP COLUMN EmployeeNumber
  ALTER TABLE Entity ADD EmployeeNumber INT IDENTITY
failed: System.Exception : Generate schema error: 
----> System.Data.SQLite.SQLiteException : SQLite error
near "DROP": syntax error
NHibernate\DbConfiguration\NHibInitialization\SchemaManager.cs(58,0): at Smack.Core.Data.NHibernate.DbConfiguration.NHibInitialization.SchemaManager._generateNewDb(Configuration cfg, IDbConnection conn)
NHibernate\DbConfiguration\NHibInitialization\SchemaManager.cs(16,0): at Smack.Core.Data.NHibernate.DbConfiguration.NHibInitialization.SchemaManager.GenerateNewDb(Configuration cfg, IDbConnection connection)
NHibernate\TestFixtures\SQLite\SQLiteBaseTestFixture.cs(56,0): at Smack.Core.TestingSupport.NHibernate.TestFixtures.SQLite.SQLiteBaseTestFixture._buildSchema()
NHibernate\TestFixtures\SQLite\SQLiteBaseTestFixture.cs(37,0): at Smack.Core.TestingSupport.NHibernate.TestFixtures.SQLite.SQLiteBaseTestFixture._SetUpNHibernateSession()
NHibernate\TestFixtures\SQLite\SQLiteBaseTestFixture.cs(25,0): at Smack.Core.TestingSupport.NHibernate.TestFixtures.SQLite.SQLiteBaseTestFixture.OnSetUp()
Mappings\EmployeeMappingTests.cs(23,0): at Smack.ConstructionAdmin.Data.Tests.Mappings.EmployeeMappingTests.OnSetUp()
BaseTestFixture.cs(27,0): at Smack.Core.TestingSupport.BaseTestFixture.SetUp()
--SQLiteException
at System.Data.SQLite.SQLite3.Prepare(SQLiteConnection cnn, String strSql, SQLiteStatement previous, UInt32 timeoutMS, String& strRemain)
at System.Data.SQLite.SQLiteCommand.BuildNextCommand()
at System.Data.SQLite.SQLiteCommand.GetStatement(Int32 index)
at System.Data.SQLite.SQLiteDataReader.NextResult()
at System.Data.SQLite.SQLiteDataReader..ctor(SQLiteCommand cmd, CommandBehavior behave)
at System.Data.SQLite.SQLiteCommand.ExecuteReader(CommandBehavior behavior)
at System.Data.SQLite.SQLiteCommand.ExecuteNonQuery()