OK, I feel like I'm missing something really obvious. Here's the issue ...
I am using an IEntityValidator derived class for validating both field and entity level variables. Right now I'm not using any of the field level Validators generated by LLBL. The problem is that I can't catch the exceptions.
Here's the Validation code:
class ItemEntityValidator : IEntityValidator
{
bool IEntityValidator.Validate(object containingEntity)
{
ItemEntity entity = (ItemEntity)containingEntity;
//Field level validation
if (entity.Descr.Length < 5)
{
throw new ORMEntityValidationException("Description Length must be at least 5 characters long.", entity);
}
//If exception not thrown, it's valid
return true;
}
}
And here's the code that saves the entity and generates the exception:
public bool SaveItem(ItemEntity itemToSave)
{
Boolean retVal = false;
//Validate before saving
itemToSave.EntityValidatorToUse = new ItemEntityValidator();
try
{
using (DataAccessAdapter adapter = new DataAccessAdapter(DBConnection.ConnectionString))
{
retVal = adapter.SaveEntity(itemToSave, true, null, false);
}
}
catch (ORMEntityValidationException ex)
{
Console.WriteLine("caught it");
}
return retVal;
}
As expected, I can save invalid data and the Validator throws the ORMEntityValidationException. But the Manager class that calls SaveEntity isn't catching it (receive an Unhandled Exception for ORMEntityValidationException). What am I doing wrong?
Thanks in advance,
Josh Lindenmuth