Почему HBM2DDL.SchemaExport здесь не работает?
-
12-10-2019 - |
Вопрос
Попытка поиграть с iinterceptor в Nhibernate 2.1.2.4000 У меня есть следующий бит тестового кода:
public class TestingNHibernateInterceptors
{
[Fact]
public void can_intercept_delete_for_audit_log()
{
FullyConfigureDb();
Session(s => s.Linq<Person>().Any().ShouldBe(false));
}
ISessionFactory _sessions;
void Session(Action<ISession> @do)
{
using (var s = _sessions.OpenSession())
{
@do(s);
s.Flush();
}
}
void FullyConfigureDb()
{
var cfg = CreateConfig();
_sessions = cfg.BuildSessionFactory();
BuildSchema(cfg);
}
Configuration CreateConfig()
{
return Fluently.Configure()
.Database(new SQLiteConfiguration().InMemory())
.Mappings(x => x.FluentMappings.Add<PersonMap>())
.BuildConfiguration()
.SetProperty("proxyfactory.factory_class", "NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle")
.SetProperty("show_sql", "true");
}
void BuildSchema(Configuration config)
{
var se = new NHibernate.Tool.hbm2ddl.SchemaExport(config);
se.Execute(false, true, false, _sessions.OpenSession().Connection, null);
}
public class Person
{
public virtual Guid Id { get; private set; }
public virtual string Name { get; set; }
}
public class PersonMap : ClassMap<Person>
{
public PersonMap()
{
Id(x => x.Id);
Map(x => x.Name);
}
}
public class AuditInterceptor : EmptyInterceptor, IInterceptor
{
public override void OnDelete(object entity, object id, object[] state, string[] propertyNames, NHibernate.Type.IType[] types)
{
base.OnDelete(entity, id, state, propertyNames, types);
}
}
}
Однако. Я продолжаю получать сообщение:
Не удалось: nhibernate.adoexception: не удалось выполнить запрос [выберите счет (*) как y0_ из "человека" this_] [sql: select count (*) как y0_ из "человека" this_] ---- System.data.sqlite. SQLiteException: ошибка SQLite
Экспорт схемы, кажется, работает - почему таблица не создается?
Я предполагаю, что это как -то связано с использованием SQLLITE в памяти, но не уверен, в чем проблема. Любые идеи?
Решение
Не связан с StackOverflow