© 2026 Hedgehog Software, LLC

TwitterGitHubDiscord
More
CommunitiesDocsAboutTermsPrivacy
Search
Star
Setup for Free
C#C
C#•3y ago•
18 replies
Filomeon

❔ Data Layer communicating ultimately to API controller

Hello 👋
I was wondering if someone has a best practice for this? 😁

I want that my Data Access Layer (Repository using Entity framework) communicates to my API controller to tell it if :

1) If the item to update was not found with corresponding ID in DB
2) If the item to update can not be updated because some item in DB already uses its UNIQUE name
3) If the item has successfully been updated

Usually I return to my API the Item if success, or null if not found. But here, I must also communicate if item with unique name already exists, and the controller must know so that I can return valuable info to the API consumer.

Do you think that throwing Exception from the data access layer, bubbling it to my Business Layer, and finally catching it in my API Controller is a good idea?

I have doubts because some people say exceptions should really be exceptional, and I don't feel like these Database Update impossibilities are really exceptional ? 🤔
Is there another better way to do this ?

Any help will be very much appreciated ! 👍
C# banner
C#Join
We are a programming server aimed at coders discussing everything related to C# (CSharp) and .NET.
61,871Members
Resources

Similar Threads

Was this page helpful?
Recent Announcements

Similar Threads

❔ How to properly handle exceptions between API controller and service layer?
C#CC# / help
3y ago
Presentation layer vs business layer vs data layer
C#CC# / help
5mo ago
✅ Passing data from controller to view
C#CC# / help
4y ago
Blazor WebAssembly API Controller
C#CC# / help
12mo ago