Skip to main content
Home Forums Silverlight Programming WCF RIA Services Entity validation problem
4 replies. Latest Post by sapientcoder on July 1, 2009.
(0)
sapientc...
Member
222 points
69 Posts
06-30-2009 7:23 PM |
Inside of the Save() routine in one of my ChildWindows, I have code like this:
if (dataForm.IsItemValid) { _context.SubmitChanges(); _context.Submitted += (sender, args) => { // handle exceptions from submit operation }; }
The entity being edited by the DataForm has an "Address" property that points to an Address entity, which has several required fields and is an associated (child) entity.
For some reason, if I fill out a couple of fields on the DataForm and then click OK (without filling out any Address fields), the IsItemValid property returns "true" and tries to save the entity to the server, even though its address in invalid. As a result, I get an exception back from the server. In other cases, however (like if I leave the whole form blank and don't try filling out anything before saving), the IsItemValid property returns the correct value and doesn't try to save the entity (which makes sense since the Address is invalid).
Has anyone else seen this happen?
Klinger
Participant
1686 points
300 Posts
06-30-2009 7:35 PM |
Nothing really to do with the problem you are describing but shouldn't the call to SubmitChanges be after
the event subscription?
_context.Submitted += (sender, args) => { // handle exceptions from submit operation };_context.SubmitChanges();
07-01-2009 9:45 AM |
It's correct in the actual code. I hand-wrote the snippet in the post yesterday, and I got those two lines backwards.
Also, just for what it's worth to anyone reading this, we're getting ready to ditch the DataForm control and see how difficult it really is to just write our own data entry forms (or use 3rd-party controls) and handle validation ourselves.
ColinBlair
Contributor
6579 points
1,291 Posts
07-01-2009 10:12 AM |
sapientcoder: Also, just for what it's worth to anyone reading this, we're getting ready to ditch the DataForm control and see how difficult it really is to just write our own data entry forms (or use 3rd-party controls) and handle validation ourselves.
You should checkout Karl Shifflett's XAML Power Toys for generating business forms, it is what I use in my production systems.
07-01-2009 1:06 PM |
Thanks! I took your suggestion and tried XAML Power Toys, and that add-in definitely makes things easier. Now the prospect of going without the DataForm doesn't seem as daunting.
The only issue left to solve now is how to duplicate some of the nice eye candy that the DataForm provides when handling validation errors. I'll have to dig in with Reflector and figure out what styles, etc. it's using to provide those nice visual effects.