Print Page | Close Window

Non-nullable makes empty string invalid?

Printed From: IdeaBlade
Category: DevForce
Forum Name: DevForce 2010
Forum Discription: For .NET 4.0
URL: http://www.ideablade.com/forum/forum_posts.asp?TID=3369
Printed Date: 07-May-2024 at 2:10am


Topic: Non-nullable makes empty string invalid?
Posted By: alexander
Subject: Non-nullable makes empty string invalid?
Date Posted: 02-Apr-2012 at 4:44am
I have some entities, some of which have non-nullable string properties. If I set these to an empty string, though, and attempt saving them, I get the following unexpected error message:

"FieldName is required"

Yeah, well, I set FieldName to something, I set it to "". Why does your code treat "not null" as "not empty string"? They are not the same thing.



Replies:
Posted By: sbelini
Date Posted: 02-Apr-2012 at 10:46am
Hi alexander,
You should set ShouldTreatEmptyStringAsNull to false:
 
entityManager.VerifierEngine.DefaultVerifierOptions.ShouldTreatEmptyStringAsNull = false;
 
You can also find this information in the http://drc.ideablade.com/xwiki/bin/view/Documentation/validation-configure#HShouldTreatEmptyStringAsNull - DevForce Resource Center .
 
Regards,
   Silvio.


Posted By: alexander
Date Posted: 13-Apr-2012 at 3:49am
I tried doing that, but I still get the same exception. I don't think I'm setting the DefaultVerifierOptions too late either, it's the first thing I do after instantiating my EntityManager.

I noticed upon catching the exception that the DefaultVerifierOptions.ShouldTreatEmptyStringAsNull setting was false, but that a Non-Public member of the VerifierEngine has a field "_verifierOptions" where the setting was true. I assumed those are the settings being used, not the DefaultVerifierOptions.

This behavior can be verified by creating an instance of the entity manager and setting the DefaultVerifierOptions.ShouldTreatEmptyStringAsNull setting to false, and then breaking and looking at the following value in the Watch window: ((IdeaBlade.EntityModel.EntityManager)(entityManager)).VerifierEngine._verifierOptions.

However, even correcting that value didn't fix my problem. I tried changing it through the Watch window, and I STILL get the exception. This issue truly has me baffled.

I also noticed there was a IdeaBlade.Validation.VerifierOptions.SystemDefault which also has ShouldTreatEmptyStringAsNull. I'm not allowed to modify that one, however, so I can't tell if it influences anything.


Posted By: sbelini
Date Posted: 13-Apr-2012 at 11:04am
Have you changed it in the server as well?


Posted By: alexander
Date Posted: 17-Apr-2012 at 5:27am
This is on the server. Or, rather, it's in a Console Application. There's no client/server relationship here, I'm working directly against the project with the edmx file and the IB.Designer.cs file in it.


Posted By: sbelini
Date Posted: 17-Apr-2012 at 2:14pm
Hi Alexander,
 
Even if this is a console application (i.e. 2-tier app) you still have the concept of client and server.
 
When you set:
 
myEntityManager.VerifierEngine.DefaultVerifierOptions.ShouldTreatEmptyStringAsNull = false;
 
in your console app, it's as if you were changing the VerifierEngine options in the client.
 
You'd still need to change this setting in the server. You would be able to do that via SaveInterceptor:
 
  class SaveInterceptor : EntityServerSaveInterceptor {
      protected override bool ValidateSave() {
      EntityManager.VerifierEngine.DefaultVerifierOptions.ShouldTreatEmptyStringAsNull = false;
      return base.ValidateSave();
    }
  }
 
Regards,Silvio.



Print Page | Close Window