4

I am using EF 6 as my ORM. I am trying to decide how to handle CRUD failures.

Option 1:

Use exceptions (custom or built-in) to inform the web layer that an item didn't correctly save. Handle the exceptions at the Web Layer as either error messages to the user or to trigger an AJAX post to try again depending on the reason for the failure.

Option 2:

Use some sort of object as a wrapper for CRUD operations. Return an enum and a message. Writer an object parser at the Web Layer as either error messages to the user or to trigger an AJAX post to try again depending on the reason for the failure.

I am also open to other ideas. These are the two that I have come up with.

I am using DB first on a legacy database. This database structure is poor at the very best. The current way issues are handled, is by returning an object that holds an enum and message. The majority of the applications hitting the database is used in winform apps. I just happen to be writing the web applications that hit them.

  • Do you expect a lot of failures when interacting with your database? Validations should be performed client side, with an additional check when posting the form. If your database structure is correctly set up, then the only time EF might throw an exception, would be due to issues outside of your control, in which case, catch the exception and present the user with a generic error message, as they don't need details anyway. You should also then log the exception, so you could then examine the cause of the problem. – Tobias Jul 29 '14 at 16:01
  • @Tobias "If your database structure is correctly set up" I am dealing with a legacy database that isn't set up very well. see my update – Robert Jul 29 '14 at 16:06

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.