Nhibernate删除doens工作

时间:2016-10-19 19:54:29

标签: nhibernate

  

我试图用NHibernate删除。我必须先删除   tItemVantagem和tItemDesconto然后是tContraCheque。那些表   由FK IdContraCheque连接。它似乎工作,我没有任何异常或错误。抱歉帖子的风格,这是我的第二次尝试

public void ExcluirContraCheque(int competencia)
        {
            ITransaction transaction = _session.BeginTransaction();

            string hqlItemDesconto = @"delete id from tItemDesconto id 
                                        join tContraCheque cc on id.IdContraCheque = cc.IdContraCheque 
                                        where cc.IdCompetencia = :competencia";

            string hqlItemVantagem = @"delete id from tItemVantagem id 
                                        join tContraCheque cc on id.IdContraCheque = cc.IdContraCheque 
                                        where cc.IdCompetencia = :competencia";
            try
            {
                _session.CreateQuery(hqlItemDesconto)
                        .SetParameter("competencia", competencia)
                        .ExecuteUpdate();

                _session.CreateQuery(hqlItemVantagem)
                        .SetParameter("competencia", competencia)
                        .ExecuteUpdate();

                _session.CreateQuery(@" DELETE FROM tContraCheque WHERE IdCompetencia = :competencia")
                        .SetParameter("competencia", competencia)
                        .ExecuteUpdate();

                transaction.Commit();
            }
            catch (Exception)
            {
                transaction.Rollback();
            }
        }
  

SQL Server查询:

    delete id from tItemDesconto id 
inner join tContraCheque cc  on id.IdContraCheque = cc.IdContraCheque
where cc.IdCompetencia = @IdCompetencia

delete id from tItemDesconto id 
inner join tContraCheque cc  on id.IdContraCheque = cc.IdContraCheque
where cc.IdCompetencia = @IdCompetencia

0 个答案:

没有答案