在哪里引用session.BeginTransaction?

时间:2010-07-28 06:56:57

标签: nhibernate transactionscope

必须使用的dll是什么?我在哪里可以买到它?

我正在使用Nhibernate,我可以将它与NHibernate一起使用吗?

2 个答案:

答案 0 :(得分:1)

BeginTransaction()是NHibernate会话的一个方法。它是当前版本的NHibernate中NHibernate.dll的一部分。

答案 1 :(得分:0)

来源:http://www.fincher.org/tips/Languages/NHibernate.shtml

using (ISession session = OpenSession()) {
  using (ITransaction transaction = session.BeginTransaction()) {
    IQuery query = session.CreateQuery("FROM Pet WHERE PetName = 'Rosie'");
    Pet pet = query.List<Pet>()[0];
    session.Delete(pet);
    transaction.Commit();
  }
}


static ISessionFactory SessionFactory;
static ISession OpenSession() {
  if (SessionFactory == null) //not threadsafe
      { //SessionFactories are expensive, create only once
    Configuration configuration = new Configuration();
    configuration.AddAssembly(Assembly.GetCallingAssembly());
    SessionFactory = configuration.BuildSessionFactory();
  }
  return SessionFactory.OpenSession();
}

http://www.google.com/search?q=session.begintransaction+nhibernate