Hi, thanks for the reply. I think I'm on a different track though. I'll try and explain using code samples;
Using the adapater approach, I have a generated CustomerEntity class which I've coded a Validator class for.
Public Class CustomerEntityValidator
Implements IEntityValidator
Public Function Validate(ByVal containingEntity As Object) As Boolean Implements IEntityValidator.Validate
Dim Customer As CustomerEntity = CType(containingEntity, CustomerEntity)
Try
If Customer.Title = "" Then
Throw New ORMEntityValidationException("Customer Title is a required field.", containingEntity)
End If
Catch ValidationException As ORMEntityValidationException
Throw
Catch ex As System.Exception
Throw
End Try
End Function
End Class
I have coded a manager class called CustomerManager that has a function called SaveCustomer. Here's the code (cut down) for it;
Public Function SaveCustomer(ByVal CustomerObject As CustomerEntity) As Boolean
Dim myAdapter As New DataAccessAdapter
Dim CustomerValidator As IEntityValidator = New CustomerEntityValidator
CustomerObject.EntityValidatorToUse = CustomerValidator
Try
Return myAdapter.SaveEntity(CustomerObject)
Catch ValidationException As ORMEntityValidationException
Throw
Catch ex as System.Exception
Throw
End Try
End Function
With the simple example above, if my Validator class (CustomerValidator) throws an ORMEntityValidationException exception, then it is not caught in the above "Try" block. The debugger tells me that the ORMEntityValidationException is not handled.
If I insert the following lines of codes in the above SaveCustomer function before the call to SaveEntity, I can catch the ORMEntityValidationException exception okay.
Try
CustomerObject.Validate
Catch ValidationException as ORMEntityValidationException
Throw
End Try
So functionally, I can acheive what I'm after by inserting an implicit call to Entity.Validate. But technically, this means I execute the Validate event twice because it's call by the Data Access Adapter also. I'd like to be able to catch the ORMEntityValidationException exception in my Try block that houses the call to myAdapter.SaveEntity so that the Validate method gets executed once only.
I appreciate the help. (Sorry about the lack of indentation on the code samples - can't figure out how to do that).
Kind Regards
Antony