Jul 4, 2007 at 5:52 AM
Edited Jul 4, 2007 at 5:56 AM
How do you go about validating properties of two different objects that have no direct link with each other.
Let us say we have this case.
Imagine we have these 2 classes (btw I just made it up , maybe you can come up with a better scenario than this to formulate what I intend to do),
and I have this rule whereby an employee is not an eligible for a discount on their purchases given that their hire date should not fall between the discount effective and end date.
The validation should occur before placing the order and there is no link between the order and the discount class either.
My questions are
How to do that kind of validation
Where it should be placed ie in order, employee, order or a non entity class and using which validating method.
My class generator restricts me from tailoring properties with attributes , so I can only extend an entity class through using partial class using
Self Validation methods or through configuration file.
I don't see how this could ever work unless there is a predictable way of locating
which instance of the Discount class relates to the specific instance of the Employee class. Conceivably you could define your own validator that used reflection to check a property of one object against a property in another one (keeping in mind that
the reflection approach wouldn't work with the UI integration layers), however this would still need a way to identify the relevant instances, eg:
public Discount GetDiscountFor(Employee e)