Skip to main content

Microsoft Silverlight

Answered Question Entity validation problemRSS Feed

(0)

sapientcoder
sapientc...

Member

Member

222 points

69 Posts

Entity validation problem

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?

-------------------
Bart McDonough
www.inclinetechnical.com

(Please remember to select Mark as Answer on a post that answers your question so others can benefit from the solution.)

Klinger
Klinger

Participant

Participant

1686 points

300 Posts

Re: Entity validation problem

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();

 

sapientcoder
sapientc...

Member

Member

222 points

69 Posts

Re: Entity validation problem

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.

-------------------
Bart McDonough
www.inclinetechnical.com

(Please remember to select Mark as Answer on a post that answers your question so others can benefit from the solution.)

ColinBlair
ColinBlair

Contributor

Contributor

6579 points

1,291 Posts

Answered Question

Re: Entity validation problem

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.

-Colin Blair

http://www.RiaServicesBlog.net : The Elephant Guide to RIA Services
SLColinBlair on Twitter

sapientcoder
sapientc...

Member

Member

222 points

69 Posts

Re: Re: Entity validation problem

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.

-------------------
Bart McDonough
www.inclinetechnical.com

(Please remember to select Mark as Answer on a post that answers your question so others can benefit from the solution.)
  • Unanswered Question
  • Answered Question
  • Announcement
Microsoft Communities