Csla.Validation.ValidationException: Object is not valid and can not be saved

Csla.Validation.ValidationException: Object is not valid and can not be saved

Old forum URL: forums.lhotka.net/forums/t/2413.aspx


gdk9am posted on Thursday, February 22, 2007

Hi All

I get "Csla.Validation.ValidationException: Object is not valid and can not be saved" when I do the following in the Project Tracker example

1. edit a project

2. make end date less than start date

3. Click "OK"

4. Get exception dialog box "Csla.Validation.ValidationException: Object is not valid and can not be saved"

How do I fix this ?

 

mr_lasseter replied on Thursday, February 22, 2007

This is the desired behavoir.  You cannot save objects that are not valid.  Did the error provider not display by end date?

gdk9am replied on Thursday, February 22, 2007

Yes, however should this exception be displayed to the end user ?

mr_lasseter replied on Friday, February 23, 2007

Do

 

Try

object.Save

Catch ex as ValidationException

'--Put your code here to do what you want, probably display message with list of broken rules

End Try

Cslah replied on Thursday, June 28, 2007

I've found this happening to me automatically from a DataGridView in some obscure cases. Not sure why, but the grid actually tries to save the BO in some cases, even though the object isn't valid. What I had to do is override Save, with this:

public override BusinessBaseObject Save()
{
   
if (this.IsValid == true)
      
return base.Save();
   
else
      
return this;
}

RockfordLhotka replied on Friday, June 29, 2007

You are using an EditableRootListBase I assume?

Can you be more specific about the scenario where this occurs? This should not happen, and so it would be nice to trace down the scenario and see if it is a bug in ERLB.

Copyright (c) Marimer LLC