我正在尝试通过映射来设置带有 Nhibernate 代码的会话工厂,但是我在配置它时遇到了问题,而且通过与会话工厂的映射很难找到代码指南。
自动取款机。我有这个 SessionManager,但我不确定在哪里指定它的 MySQL 数据库,很容易错过更多。
public class SessionManager
{
private const string ConnString = "Server=localhost; Port=3306; Database=test; Uid=root; Pwd=123456;";
public static SessionManager CurrentInstance
{
get
{
if (_currentInstance == null)
{
object sync = new object();
lock (sync)
_currentInstance = new SessionManager();
}
return _currentInstance;
}
}
public static ISession Session
{
get
{
if (_sessionFactory == null)
{
object sync = new object();
lock (sync)
_sessionFactory = new Configuration()
.DataBaseIntegration(x => x.ConnectionString = ConnString)
.Configure()
.AddAssembly(typeof(EmployeeMap).Assembly)
.BuildSessionFactory();
}
return _sessionFactory.OpenSession();
}
}
private SessionManager() { }
static SessionManager _currentInstance;
static ISessionFactory _sessionFactory;
}