From the course: Practical Application Architecture with Entity Framework Core

Unlock the full course today

Join today to access over 22,600 courses taught by industry experts or purchase this course individually.

DbUpdateException

DbUpdateException - Entity Framework Tutorial

From the course: Practical Application Architecture with Entity Framework Core

Start my 1-month free trial

DbUpdateException

- [Narrator] Having seen the DB update exception in the last chapter, it deserves a little more thought in the architecture. It is not desirable for them to bubble all the way up to the UI, and often, it can be valuable to contain them within the data layer. One of the advantages to isolating the EF context to the data layer is the ability to handle data-level exceptions within the DAL. Database access errors can be isolated from the shared code by using custom application exceptions after handling the DB exceptions in a way that makes sense for the data layer. Perhaps something like emailing the database administrator directly so that the issue can be handled quickly. The business layer would handle the application exception as part of the business logic. For an example of this, we'll start in the Tracking Repository in the DAL. Since database update exceptions can only happen when the database is updated we can add error handling logic in the SaveChanges method at the bottom. We'll…

Contents