Is it possible to create a validation rule that will check a users input against values in a database table. For example if my database contained a table that stores the list of all valid US zip codes. I would like to create a validation rule that will check the users input in the zip Code entry field against the valid zip codes in the table.
And if so is it possible to only have this type of validation occurs when the user chooses to save the form instead of doing it when the user tabs off the field which could cause a delay as it goes back to the server to do the check.
Thanks
Yes. To do this, you can either use a ReadOnlyBase or CommandBase object - which is often private and nested within your business object to avoid cluttering the object model (either that, or put it in a sub-namespace).
You can see how a command object like this might work by looking at how the Equals() methods are implemented in Project and Resource, as discussed in Chapter 7. In your case however, you probably won't have a public static/Shared method like Equals(), but rather will have a private method that invokes the command.
You can invoke the command from within a rule method - but in that case it would run any time CheckRules() is called for the associated property, which doesn't sound like what you want.
So instead, you can override Save() and call it there.
Rocky did you mean to look at how the Equals() or Exists() method are implemented in Project and Resource ?
From: Steven [mailto:cslanet@lhotka.net]
Sent: Tuesday, May 30, 2006 9:32 PM
To: rocky@lhotka.net
Subject: Re: [CSLA .NET] Validation Rule QuestionRocky did you mean to look at how the Equals() or Exists() method are implemented in Project and Resource ?
Copyright (c) Marimer LLC