2010-12-24 11 views
3

私は、次のテストケースで特に混乱しています:あなたが見ることができるように、私はautomappingsを試していの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(); 
    } 
} 

が、残念ながら次のテストケースを提起

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

私はあなたが2つのセッションを使用していると思います。 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);