kids_pro posted on Thursday, March 22, 2007
I tried to implement a simple custom validation rule "NoDuplicate" but it doesn't seem to work well.
I got the following error message when I tried to load the Parent object.
Exception Details: System.NullReferenceException: Object reference not
set to an instance of an object.
Line 192: private bool NoDuplicate(object sender, Csla.Validation.RuleArgs e) { Line 193: Beneficiaries parent = (Beneficiaries)this.Parent; Line 194: foreach (Beneficiary b in parent) { Line 195: if (b.VillGis == _villGis && !ReferenceEquals(b, this)) { Line 196: e.Description = "This village already exist in beneficiary list."; |
I add the NoDuplicate like this:
protected override void AddInstanceBusinessRules() {
ValidationRules.AddInstanceRule(NoDuplicate, "VillGis");
}
To clarify here is the class diagram
I don't know if it necessary to call MarkAsChild() in the Beneficiary constructor or not?
If this error cause by my call to ValidationRules.CheckRules() in the Beneficiary constructor?
My NoDuplicate rule is simple: Project has beneficiary which identify by location, and the location can't appear more than one.