I have an Entity Framework configured to update a table. The update is intercepted instead of the trigger that calls RAISERROR:
CREATE TRIGGER mySchema.UpdateBusinessObjects ON mySchema.BusinessObjects INSTEAD OF UPDATE AS RAISERROR(''test error from SQL'',16,1) RETURN
In my repository class, I am trying to catch the SqlException thrown by RAISERROR in SQL:
public void SaveBusinessObject(BusinessObject b) { try { repo.Entry(b).State = EntityState.Modified; repo.SaveChanges(); } catch (SqlException ex) {
The problem is that C # does not catch a SqlException; it is passed to the caller as an unhandled exception ("SqlException was unhandled by the user: test error from SQL"). What kind?!
It looks like EF SaveChanges () is somehow throwing an exception on top of my catch try block. I tried switching my catch statement to catch (Exception ex) in case the EF exception is somehow more general, but I still get the unhandled SqlException exception. Am I missing something here? What is the problem with the SaveChanges () method?
user941238
source share