I am particularly confused by the following test case:
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();
}
}
As you can see, I'm experimenting with automappings, but unfortunately the following test case raises the following SQLite exception (the first contains the actual queries done):
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)
)
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
And I can't understand why does it happen this way - the SQL commands seem to be working appropriately and the corresponding table should be created by the create table
query.
I assume something is wrong in my code (I probably missed something). Could you help me?
I think your using two sessions. One during database creation and in your test proper. Try setting up like this.
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);