locked
Screen validation error, yet saves anyway?? RRS feed

  • Question

  • I have a strange problem. I recently changed a datagrid for a many-to-many relationship to use RIA Services instead of my database workspace. I also recently updated WCF Data Services to 5.0.0.

    Now when I type an error in this datagrid, its validation method adds a screen error as usual. This works fine, and the error is displayed at the top of my screen. However for some bizarre reason when I click save it actually saves! It doesn't pop-up "Unable to save data" like I would expect. The invalid data is written to the database (fails if I've a check constraint on the Db).

    I've played with a few things, like commenting out my Screen_Saving() method. (No change.) The screen error is definitely detected in my saving code:

    partial void TimeSheets_Saving(ref bool handled) {
    	if (Details.ValidationResults.HasErrors) {
    		// this executes as expected
    		return;
    	}
    	// do a couple minor things
    }

    I'm at a loss for how to fix this. The property errors and screen errors on other controls on my screen work perfectly fine, I can't save and get the usual "Unable to save data" message. Also as far as I'm aware I *used* to get this as well before I changed that particular data grid to work from RIA Services. There is no other data workspace on this screen now, it's all RIA Services - the screen is set to use the correct data workspace and code for saving to multiple data workspaces has long been removed. Saving validation works fine other than this, my other two data grids work perfectly fine (neither is a many-to-many though).

    Changing it from a ScreenError to a PropertyError made no difference, it still shows a validation error as normal but then saves perfectly fine.

    I tried handled = true in the if block above, and that prevents saving but doesn't alert the user. Also it's a problem because that avoids/hides the "Unable to save data" message for *everything*.

    What's going on? I thought saving shouldn't be allowed with a screen error under any circumstances.

    Edit: This is working as a workaround for now:

    partial void TimeSheets_Saving(ref bool handled) {
    	if (Details.ValidationResults.HasErrors) {
    		if (Details.Properties.DayExperience.ValidationResults.HasErrors) {
    			handled = true;
    			this.ShowMessageBox("Please correct data entry errors and try to save again.", "Unable to save data", MessageBoxOption.Ok);
    		}
    		return;
    	}
    }


    Friday, April 5, 2013 2:51 PM