2011-01-18 4 views
0

DB가 자동으로 EmployeeId #를 증가 시키길 원합니다. 이것은 비즈니스 id 일 것이고 db id (생성 된 hilo)와 동일하지는 않습니다. promising solution처럼 보이지만 구현하는 데 문제가 있습니다.id가 아닌 NHibernate 증가 열

매핑이 잘못되었거나 SQLite에서 처리 할 수 ​​없기 때문에 예외가 발생했는지 여부를 알 수 없습니다. 나는 또한 누군가가 이것에 대한 다른 해결책을 가지고 있는지 알고 싶다.

건배,
베리

매핑 테이블 변경 SQLite는 문 here에 대한 플로우 차트에서

<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> 

예외 출력

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() 

답변

1

, 나는 DROP 절을 찾을 수 없습니다. 열을 추가하고 이름을 바꿀 수만 있습니다. 따라서 EmployeeNumber를 삭제하는 대신 EmployeeNumber_old로 이름을 바꿀 수 있습니다. 또한 전체 테이블을 삭제하고 다시 만들 수도 있습니다 (그러나 프로덕션 데이터가 포함 된 영구 SQLite DB 인 경우 이에 대해 조언합니다)

관련 문제