How do I create a custom validator that tests two properties at once?

Topics: Validation Application Block
Dec 6, 2008 at 3:25 PM

In my database, I have a composite unique key constraint (CustomerId, Name) on a entity. I want to test if the unique constraint is upheld before submitting to the database. The user can customize the Name attribute on the entity, so I would like to make a custom validator that validates the name property, but while doing it, I need access to the CustomerId property as well. How do I do that?

I an using WCSF, which means I am stuck in Entlib 3.1 and the included VAB.

Regards, Egil.
Dec 7, 2008 at 3:26 PM

You can try using Self-Validation. See this link:

Valiant Dudan
Global Technology and Solutions
Avanade, Inc.
Dec 7, 2008 at 5:24 PM
Hi Valiant

I could not figure out how to get the PropertyProxyValidator control use the Self-Validation method, which is want I want. So I ended up extending PropertyProxyValidator, adding a new property named SateliteData and getting the desired result.

Dec 8, 2008 at 9:06 AM
I wouldn't expect it to since SelfValidation occurs when you perform validation on an object of that certain type of class which has the HasSelfValidation attribute.  You can also opt to use the ValueConvert event of the PropertyProxyValidator and perform there the validation of your object.

Sarah Urmeneta
Global Technology & Solutions
Avanade, Inc.