New Posts New Posts RSS Feed: null for integer doesn't verify
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

null for integer doesn't verify

 Post Reply Post Reply
Author
GregD View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 09-May-2007
Posts: 374
Post Options Post Options   Quote GregD Quote  Post ReplyReply Direct Link To This Post Topic: null for integer doesn't verify
    Posted: 29-May-2008 at 4:52pm
DataMan:
 
[Sorry for the delay. I attempted to post this on Tuesday, but for whatever reason it doesn't seem to have made it to the forum.]
 
In order for a verification error to be diagnosed upon *setting* the SortOrder value, you would need a call to BeforeSetValue() in the SortOrder setter.  You can code the call to BeforeSetValue() yourself in the setter in your SortOrder override, or you can get the Object Mapper to generate it for you (into the base class).
 
To do the latter, open the Verifications Options dialog and select the RadioButton to turn verification code generation On. Having done that, you can still turn off the generation of attributed verifiers by unchecking the "Generate predefined verifiers" CheckBox. You can also turn off the generation of BeforeSetValue() or AfterSetValue() calls, as the default, by selecting "Neither" in the Property Setter Options area of the dialog. Then, on the Simple Properties tab on the main Object Mapper dialog, you can turn on the generation of that call for the SortOrder property (only).
 
None of above, however, is required to make your instance verification work properly. All that is required for that is (a) to add the attribute to define the verifier (as you have done); and (b) to call instance verification and properly deal with the result.  Here's an example of using instance verification on an Employee instance:
 
    void mPersMgr_Saving(object sender, EntitySavingEventArgs e) {
      foreach (Entity anEntity in e.Entities) {
        if (anEntity is Employee) {
          Employee anEmployee = (Employee)anEntity;
          VerifierResultCollection aVerifierResultCollection = anEmployee.VerifierEngine.Execute(anEmployee);
          foreach (VerifierResult result in aVerifierResultCollection) {
            if (!result.IsOk) {
              MessageBox.Show("Employee [" + anEmployee.LastFirst + "] failed verification. Save cancelled.");
              e.Cancel = true;
              return;
            }
          }
        }
      }
    }
 
In the above code, if the IsOK property of any VerifierResult returned by the call to VerifierEngine.Execute() is false, the save is cancelled.
 
Regards,
 
Greg Dunn
IdeaBlade
 
Back to Top
DataMan View Drop Down
Groupie
Groupie
Avatar

Joined: 26-Jul-2007
Location: Canada
Posts: 52
Post Options Post Options   Quote DataMan Quote  Post ReplyReply Direct Link To This Post Posted: 23-May-2008 at 9:30am
Setup:
The Generate Predefined Verifiers option is not enabled
Sort order does not allow nulls.
SortOrder is overridden with the following:
 
[Int32RangeVerifier(MinValue = 1, IsRequired = true)]
public override int SortOrder
{
get
{
return base.SortOrder;
}
set
{
base.SortOrder = value;
}
}
 
Issue:
 
When I open the form and edit an existing record and erase the value in sort order the error icon flashes and tells me that the sort order must be greater than 1.  Which is correct and wonderful.
 
Then I run the verify code (that I grabbed from your tutorials) on the current record it passes all tests (Which it shouldn't).  When I step into the code and look at the value of sortorder in the current record of the BS it is still the old value.  This is not so wonderful.  
 
I do notice the following when the code runs an endedit with a null sortorder: 

A first chance exception of type 'IdeaBlade.Verification.VerifierResultException' occurred in IdeaBlade.Persistence.dll

When I remove the line [Int32RangeVerifier(MinValue = 1, IsRequired = true)] from the override the application then doesn't allow me to enter a null value into the field.  It automatically replaces it with 0.  But then because there is no rule on the MinValue, 0 passes the tests.  0 is an incorrect value.
 
So then I think "Well,  I'll allow null values in ideablade for the sort order field and see what happens".  On new records the record passes the verify test and says that the sort order is required which is great BUT on old records where I change the sort order to blank (null) the null sort order passes the verifier test.  Each time I change the value to null on the form I get the first chance exception error as listed above.
 
I want to be able to use either the errorproviders or the verifier engine (not both).  If the user donesn't actually change the value of a field the error providers for ideablade don't fire and if I use the verifier in the override, it doesn't work properly when null values are entered in for fields that don't allow null.  My save method checks to see if there are any errors in the verifiy code and if there are then the save cannot continue.  Because the verifier doesn't catch the null value in sort order it is allowing errors into the data.
 
Suggestions?
 
 
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down