C# 使用MySQL通过代码会话工厂设置Nhibernate映射
我试图通过映射使用Nhibernate代码来设置会话工厂,但是我在配置它时遇到了问题,而且很难通过映射会话工厂来找到代码指南 自动取款机。我有这个SessionManager,但我不确定在哪里指定它是一个MySQL数据库,可能错过了更多C# 使用MySQL通过代码会话工厂设置Nhibernate映射,c#,mysql,nhibernate,C#,Mysql,Nhibernate,我试图通过映射使用Nhibernate代码来设置会话工厂,但是我在配置它时遇到了问题,而且很难通过映射会话工厂来找到代码指南 自动取款机。我有这个SessionManager,但我不确定在哪里指定它是一个MySQL数据库,可能错过了更多 public class SessionManager { private const string ConnString = "Server=localhost; Port=3306; Database=test; Uid=root; Pwd=1234
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;
}
我认为您试图做的是指定您正在使用mysql。完成此操作后,我使用了一个NHibernate确认文件,其中有一行说明了驱动程序类别:
NHibernate.Driver.MySqlDataDriver
试试这个教程
它描述了设置nhibernate会话的过程,并显示了一个示例hibernate.cfg.xml文件。在此设置中,您需要指定MySqlDataDriver,而不是所示的SQLServerCeDriver
我不知道您是否可以在不使用hibernate.cfg.xml的情况下执行此操作