Validation Rule - Must have at least one item in a child collection.

Validation Rule - Must have at least one item in a child collection.

Old forum URL: forums.lhotka.net/forums/t/290.aspx


skagen00 posted on Tuesday, June 06, 2006

I'll use an example different from mine that is familiar.

Invoice - InvoiceLines - InvoiceLine

An Invoice must have at least one InvoiceLine would be the business requirement.

Now my property on my Invoice object for my InvoiceLines collection is read-only, of course.

Let's say I have a valid object and I remove the line from the InvoiceLines collection violating this business rule for the Invoice.

Do I need to maintain a referential link from the collection to the parent object in order to attempt to check a rule? (I don't like having these sorts of circular references but I've seen it somewhere in the framework where the link from the child to the parent is NonSerialize and NotUndoable).

 

Brian Criswell replied on Tuesday, June 06, 2006

You could attach an event handler in Invoice to _invoiceLines.ListChanged.  Then call ValidationRules.CheckRules("InvoiceLines") to see if _invoiceLines.Count > 0.

skagen00 replied on Wednesday, June 07, 2006

Thank you - worked like a charm.

Copyright (c) Marimer LLC