Error deleting entity

0

In the code below, I check the checkboxes in the ListView. When a check is checked the id assigned to that checkbox in the database, when I click again and uncheck it it should delete this id from a table in the database, however I am missing the following error:

  

"Deletion error, there is no column relationship with layout. could not   DELETE FROM LAYOUT WHERE ID =? "

foreach (ListViewItem x in lsvRecebeGrupoLayout.CheckedItems)
{
    int idlayout = Convert.ToInt32(x.SubItems[0].Text);
    lay = repolay.ConsultaPorId(idlayout);
    grupo.Id = idcbo;
    lay.GrupoLayout = grupo;

    if (x.Checked)
    {
        repolay.Alterar(lay);
    }

    if (e.Item.Checked == false)
    {
        repolay.Excluir(lay);
    }
}

Delete Method

public void Excluir(T entidade) {
    using(ISession session = FluentnHibernateHelper.OpenSession()) {
        using(ITransaction transacao = session.BeginTransaction()) {
            try {
                session.Delete(entidade);
                transacao.Commit();
            } catch(Exception ex) {
                if (!transacao.WasCommitted) {
                    transacao.Rollback();
                }
                throw new Exception("Erro de exclusão, há relação com um coluna de layout\n" + ex.Message);
            }
        }
    }
}
    
asked by anonymous 13.10.2017 / 20:02

1 answer

0

You are trying to delete a layout that already has a column associated with a foreign key. To solve the problem, delete the layout columns related to this layout before deleting the layout or place the deletion of the foreign key to delete in cascade. This will remove the layout and all columns from the two tables.

    
15.10.2017 / 08:53