NHibernate 中delete的使用方法

public virtual void DeletePerson(int id)
        {
            using(ISession session = OpenSession())
            {
                ITransaction tx = null;
                try
                {
                    tx = session.BeginTransaction();
                    session.Delete(string.Format("from PersonInfo where ID={0}", id));//其中PersonInfo对应的是一Model
                    session.Delete(string.Format("from PersonEducationalHistoryInfo where PersonID={0}", id));
                    session.Delete(string.Format("from PersonProfessionalHistoryInfo where PersonID={0}", id));
                    session.Delete(string.Format("from PersonFamilyMemberInfo where PersonID={0}", id));
                            tx.Commit();
                }
                catch(Exception ex)
                {
                    if(tx!=null)
                        tx.Rollback();
                    throw ex;
                }
            }
        }

 

posted @ 2012-08-29 23:01  Tom Fan  阅读(383)  评论(0编辑  收藏  举报