2010-12-24 6 views
3

나는 특히 다음 테스트 케이스에 의해 혼란 스러워요 : 당신이 볼 수 있듯이C 번호 - NHibernate에 질문

public void TestMapping() 
{ 
    var autoPersistenceModel = AutoMap.AssemblyOf<RepositoryEntity>().Where(
     x => x.Namespace.EndsWith("Descriptors")); 

    var configuration = Fluently.Configure() 
     .Database(SQLiteConfiguration.Standard.ShowSql().InMemory) 
     .Mappings(x => x.AutoMappings.Add(autoPersistenceModel)) 
     .ExposeConfiguration(x => new NHibernate.Tool.hbm2ddl.SchemaExport(x).Create(true, false)); 

    var sessionFactory = configuration.BuildSessionFactory(); 

    using (var session = sessionFactory.OpenSession()) 
    { 
     new PersistenceSpecification<IndicatorUnitDescriptor>(session) 
      .CheckProperty(x => x.Name, "Name1") 
      .CheckProperty(x => x.Timestamp, new DateTime(2000, 10, 10)) 
      .VerifyTheMappings(); 
    } 
} 

, 나는 automappings 실험 해요,하지만 불행히도 다음 테스트 케이스가 제기

drop table if exists "IndicatorUnitDescriptor" 

drop table if exists "StockUnitDescriptor" 

create table "IndicatorUnitDescriptor" (
    Id integer, 
    Name TEXT, 
    Timestamp DATETIME, 
    primary key (Id) 
) 

create table "StockUnitDescriptor" (
    Id integer, 
    Name TEXT, 
    Timestamp DATETIME, 
    primary key (Id) 
) 

: SQLite는 예외 다음 (첫 번째는 수행 된 실제 쿼리를 포함)
NHibernate: INSERT INTO "IndicatorUnitDescriptor" (Name, Timestamp) VALUES (@p0, @p1); select last_insert_rowid();@p0 = 'Name1' [Type: String (0)], @p1 = 10.10.2000 0:00:00 [Type: DateTime (0)] 

System.Data.SQLite.SQLiteException: SQLite error 
no such table: IndicatorUnitDescriptor 

그리고 나는 그것이 이런 식으로 일이 않는 이유를 이해할 수 없다 -는 SQL 명령은 적절하게 제대로 동작하고 해당 테이블은 create table 쿼리에 의해 생성되어야한다.

내 코드에 뭔가 잘못되었다고 가정합니다. 당신이 나를 도울 수?

답변

1

두 세션을 사용하고 있다고 생각합니다. 하나는 데이터베이스 생성 및 테스트에 적합합니다. 이런 식으로 설정하십시오.

Configuration cfg = Fluently.Configure() 
     .Database(SQLiteConfiguration.Standard.InMemory()) 
     .Mappings(m => m.HbmMappings.AddFromAssembly(_mappingsAssembly)) 
     .BuildConfiguration(); 

    var session = cfg.BuildSessionFactory().OpenSession(); 

    new SchemaExport(cfg).Execute(false, true, false, session.Connection, null);