using System; using System.Collections.Generic; using System.Text; using NHibernate; using NHibernate.Cfg; using System.Collections; namespace NHibernateHelper { public class NHibernateHelper { private static ISessionFactory factory = null; public static ISessionFactory GetSessionFactory(string dialect, string driver, string connstr) { //读取配置文件 //读取所有的映射文件--必须是嵌入资源 try { Configuration config = new Configuration().Configure();//.AddAssembly("Model"); config.Properties[NHibernate.Cfg.Environment.Dialect] = dialect;//"NHibernate.Dialect.OracleDialect"; config.Properties[NHibernate.Cfg.Environment.ConnectionDriver] = driver; //"NHibernate.Driver.OracleClientDriver"; config.Properties[NHibernate.Cfg.Environment.ConnectionString] = connstr;//"Data Source=core;Integrated Security=false;uid=cxuser;pwd=cxuser;Pooling=true;Min Pool Size=3;Max Pool Size=4"; //创建Session工厂,负责持久化的连接以及OR映射,该对象的开销比较大,一般我们建议用单例模式来实现 factory = config.BuildSessionFactory(); return factory; } catch (Exception ex) { throw new Exception(ex.Message); } } } }