I am trying to delete a record from an intermediate table, that is, from a table with a many-to-many relation. I would like to know how I can delete a record from that table because when I try to save the record I do not get an error, but the record is not deleted. The structure that I have is the following:
Tables
- PROFILE (ID_PERFIL, DESCRIPTION, STATUS)
- APPLICATIONS (ID_APLICATION, DESCRIPTION, STATUS)
- PROFILE_APPLICATIONS (ID_APPLICATION, PRO_ID)
Before using entity, what I did was that before inserting into the intermediate table, I eliminated everything in the PROFILE_APPLICATIONS table and then reinserted it with the new records that I have (I have that record in a datagridview, where the user can add and delete and finally save in the database).
I would like to know if there is a way to delete the intermediate table without having to go through the entity, that is, without doing a foreach.
This is my code:
if (dgvAplicacion.Rows.Count > 0)
{
foreach (DataGridViewRow row in dgvAplicacion.Rows)
{
var idapl = row.Cells["ID_APLICACION"].Value.ToString();
perfil.AM_PERFIL_TBL.Find(id).AM_APLICACIONES_TBL.Add(perfil.AM_APLICACIONES_TBL.Find(idapl));
}
}