如何NHibernate.Cfg.Configuration
使用System.Configuration.ConfigurationManager
App.config 将应用程序设置加载到对象?
hibernate配置也可以移动到app.config中,这简化了启动代码.请参阅NHibernate参考手册中的XML配置文件一节.
Configuration cfg = new NHibernate.Cfg.Configuration(); ISessionFactory sf = cfg.Configure().BuildSessionFactory();
在app.config中:
NHibernate.Connection.DriverConnectionProvider NHibernate.Dialect.MsSql2005Dialect Northwind NHibernate.ByteCode.LinFu.ProxyFactoryFactory, NHibernate.ByteCode.LinFu string connectionString = System.Configuration.ConfigurationManager .ConnectionStrings["Northwind"].ToString(); NHibernate.Cfg.Configuration nHibernateConfiguration = new NHibernate.Cfg.Configuration(); nHibernateConfiguration.SetProperty( NHibernate.Cfg.Environment.ProxyFactoryFactoryClass, typeof(NHibernate.ByteCode.Castle.ProxyFactoryFactory).AssemblyQualifiedName); nHibernateConfiguration.SetProperty( NHibernate.Cfg.Environment.Dialect, typeof(NHibernate.Dialect.MsSql2005Dialect).AssemblyQualifiedName); nHibernateConfiguration.SetProperty( NHibernate.Cfg.Environment.ConnectionString, connectionString); nHibernateConfiguration.SetProperty( NHibernate.Cfg.Environment.FormatSql, "true"); nHibernateConfiguration.AddAssembly(Assembly.GetCallingAssembly()); ISessionFactory oneISessionFactory = nHibernateConfiguration .BuildSessionFactory();