2010-07-28 132 views

回答

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

1

的BeginTransaction()是關於NHibernate會話的方法。它是當前NHibernate版本中NHibernate.dll的一部分。

相關問題