Hi
The problem is I want to return all of an entity's validation errors, and thought the SetEntityFieldError would be the way to go. This is my code:
protected override void OnBeforeEntitySave()
{
bool isValid = true;
if (Title == null)
{
SetEntityFieldError(
Fields[(int)DocumentFieldIndex.Title].Name,
"Title must be specified",
true);
isValid = false;
}
if (Price < 0)
{
SetEntityFieldError(
Fields[(int)DocumentFieldIndex.Price].Name,
"Price must be a valid amount.",
true);
isValid = false;
}
// ...etc...
if (!isValid)
{
throw new ORMEntityValidationException("Document validation failure", this);
}
}
As you can see I'm building up a list of entity field errors, then throwing an exception if there were any, to prevent the save from going ahead.
In my UI I do something like this:
try
{
Call busines tier save logic to save the entity
}
catch (ORMEntityValidationException eve)
{
// Here I want to extract the errors in eve.EntityValidated.DataErrorInfoErrorsPerField
// and display in a label, but that property is protected!
}
As mentioned in my previous post, I could extend the entity with a partial class that contains a new public property to expose what's in DataErrorInfoErrorsPerField, but this seems a bit unnecessary! Is there a better way of doing all this?
Thanks again
Andrew