New Posts New Posts RSS Feed: Non-nullable makes empty string invalid?
  FAQ FAQ  Forum Search   Calendar   Register Register  Login Login

Non-nullable makes empty string invalid?

 Post Reply Post Reply
Author
alexander View Drop Down
Newbie
Newbie


Joined: 13-Feb-2012
Posts: 10
Post Options Post Options   Quote alexander Quote  Post ReplyReply Direct Link To This Post Topic: Non-nullable makes empty string invalid?
    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.
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post 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 DevForce Resource Center.
 
Regards,
   Silvio.
Back to Top
alexander View Drop Down
Newbie
Newbie


Joined: 13-Feb-2012
Posts: 10
Post Options Post Options   Quote alexander Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post Posted: 13-Apr-2012 at 11:04am
Have you changed it in the server as well?
Back to Top
alexander View Drop Down
Newbie
Newbie


Joined: 13-Feb-2012
Posts: 10
Post Options Post Options   Quote alexander Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
sbelini View Drop Down
IdeaBlade
IdeaBlade
Avatar

Joined: 13-Aug-2010
Location: Oakland
Posts: 786
Post Options Post Options   Quote sbelini Quote  Post ReplyReply Direct Link To This Post 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.
Back to Top
 Post Reply Post Reply

Forum Jump Forum Permissions View Drop Down