C # - Nhibernate question

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 autocomplete, but unfortunately, the following test case raises the following SQLite exception (the first contains the actual queries):

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 don’t understand why this is happening - SQL commands seem to work properly, and the corresponding table should be created using the query create table.

I assume that something is wrong in my code (I probably missed something). could you help me?

+3
source share
1 answer

, . . .

  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);
+1

Source: https://habr.com/ru/post/1782010/


All Articles