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);
}
}
}
}