I want to check, that users table records does not have specific email already stored.
If there is, then ModelState.IsValid returns false in controller action.
I understand need of unique constraint and I understand issues with race conditions. Those are not my concern right now.
At this point I just want to make ModelState.IsValid to return false after querying data in right place and making model invalid.
Should I implement such validation:
- in
DbContext? - in my entity classes (User / Company etc.)?
- in
SomeCustomValidationclass? - directly in controller (since there I can already query the database...)
- somewhere else...
And nice bonus would be create solution reusable across all entities :)
How should I do it?