I have a problem to handle the delete operation in C# / EF. This is my code. I can delete record that is no problem. I have only problems with record that are used in other records. So he throw an exception and the user see a messagebox. But the record is still marked as delete so when I do another SaveChanges, I get a exception. Is it possible to change back the state of the record to not deleted?
public void Remove()
{
try
{
Klant deleteKlant = dbContext.Klanten.First(i => i.KlantId == Klant.KlantId);
dbContext.Klanten.Remove(deleteKlant);
dbContext.SaveChanges();
}
catch (Exception)
{
throw new ArgumentException("Wissen mislukt");
}
}