数据库操作类Session说明


Warning: Undefined array key "HTTP_REFERER" in /www/wwwroot/prod/www.enjoyasp.net/wp-content/plugins/google-highlight/google-hilite.php on line 58

1,连接数据库:
var configuration = new Configuration();
configuration.Configure(); //自动探索hibernate.cfg.xml或web.config中的nhibernate
configuration.AddAssembly(typeof(Product).Assembly); //指定加载哪个程序集,若不写,则默认加载工程本身
2, 连接完数据库后创建Session: _sessionFactory = configuration.BuildSessionFactory(); SessionFactory.OpenSession();
3,利用Session完之后,因是延迟加载,需用 _Session.Flush(); 提交更新,或者待Session销毁时自动提交,如:
using (ISession session = NHibernateHelper.OpenSession())
{
session.Save(user);
}