Hi everybody and thanks for reading.
I’m working with NHibernate and PostgreSQL, and basically I want to do two things:
- Provide user-friendly messages to errors while persisting the entities in the database
- Adapt the UI to show the errors in the specific parts (so if the name must be Unique and the user introduced one that already exists, I’d like to show the error as a tooltip of the Name textbox or whatever it is).
So I thought that finding the column where the constraint checks fails would be useful, and I’m trying to find a clean way to do this.
For example, NHibernate throws PropertyValueException when a field fails a “Not Null” constraint, and this (exception) class has a property called “PropertyName” which tells me the property that failed the constraint. This is what I want to get, but getting the column sounds easier and I think I could get the related property from the column name.
So, is there a (clean) way to extract the related column from NpgsqlException? Or something like that using NHibernate?
there is the hook ISqlExceptionConverter which is meant for this. Configure it with
or
and implement it like this