I am using NHibernate + Fluent to process the database in my application. So far, I have used SessionSource to create ISession objects. I'm a little confused now about what comes from NHibernate or Fluent, and what I really should use to create my sessions.
ISession comes from NHibernate and SessionSource from Fluent. I am creating a SessionSource from FluentConfiguration and am currently using SessionSource to create sessions. This is my function for creating sessions. The FluentConfiguration and SessionSource resources are reused:
if (_sessionSource == null)
{
_cfg = Fluently.Configure().Database(SQLiteConfiguration.Standard.ShowSql().UsingFile("test.db"));
_sessionSource = new SessionSource(_cfg.BuildConfiguration().Properties, new MappingsPersistenceModel());
var session = _sessionSource.CreateSession();
_sessionSource.BuildSchema(session);
return session;
}
return _sessionSource.CreateSession();
Does this look reasonable? It sounds more attractive to use ISessionFactory to create sessions, so I tried using it. This comes from NHibernate, so I don’t know why this is a problem, but it fails when my sessions are created from ISessionFactory.
_sessionFactory = _cfg.BuildSessionFactory();
_sessionFactory.OpenSession()
Using this, I get a MappingExceptionwhen using the session, saying "No persister for: MyProject.Model.SomeModelClass".
Should I keep using SessionSource? Or am I missing something regarding the ISessionFactory?
source
share