Validation issue when LLBLGEN binded directly to view

Posts   
 
    
dm.Frank
User
Posts: 21
Joined: 26-Apr-2013
# Posted on: 17-Mar-2016 08:33:31   

I am using WPF textbox control with LLBLGen Pro as ORM in my project. I am facing a strange issue with validation . following are the points.

  1. The issue only comes up when the Value field of control is directly bind to Entity's field. To replicate this issue and better clarification I have implemented it in a demo project with my view model.
  2. The "StudentEntityField.UserName" field in "StudentValidator" class have null,'' as invalid values, so red border should be shown on this.
  3. Please run the demo attached project (ValidationIssueLLBLGEN.sln) you will see one text field with "a" in it. click on it and set the cursor to end of field.
  4. Now press "Backspace" in textfield only one red border will be there, which is correct, but "a" will still be written with the validation border.

It looks like that when we delete the last "a", which is a valid value for UserName, the StudentEntityField.UserName internally fallbacks to its last valid value which is still "a", which causes a problem with the GUI error handling mechanism of WPF. Is there a common (general) approach through which I can handle this problem (I still want to bind my entity directly to UI control), I think if we can disable this behavior of entity to fallback to last valid value then this issue can be resolved, Any suggestions on this approach?

Attachments
Filename File size Added on Approval
ValidationIssueLLBLGEN.rar 629,649 17-Mar-2016 10:55.24 Approved
Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 17-Mar-2016 19:07:43   

I think the same issue was discussed in details here: http://llblgen.com/TinyForum/Messages.aspx?ThreadID=16694

dm.Frank
User
Posts: 21
Joined: 26-Apr-2013
# Posted on: 18-Mar-2016 07:14:56   

Thanks for sharing the post, I have read it, and have given try to code in http://llblgen.com/tinyforum/Messages.aspx?ThreadID=14244&StartAtMessage=0&#79435, but problem is still there.

All I want to know, Is it possible to set an invalid value to entity? from the thread you have shared it looks like it is not possible?

Walaa avatar
Walaa
Support Team
Posts: 14950
Joined: 21-Aug-2005
# Posted on: 18-Mar-2016 09:32:53   

Yes, it's not. An invalid value can't be set to a field... (hence the name invalid). You can have a default value be set in that case, and still set an error and mark the control red. (like: "please enter a value").

Anyway, as said in the thread, LLBLGen validation should not be used in the UI, that's a low level one. And you can always validate at the entity level upon submission.