Save a collection of invalid objects through the dataportal.

Save a collection of invalid objects through the dataportal.

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


MadGerbil posted on Friday, September 05, 2008

Can a collection of invalid objects be saved through the DataPortal_Update?   Right now, it seems to block that save; however, I want the save to occur because the objects are being edited and the user has the option to come back to them and fix 'em later.

 

 

skagen00 replied on Friday, September 05, 2008

I think, in part, this is why warnings were introduced - though there's a semantic difference, I suppose.

The least intrusive way I can think of doing this would be to perhaps provide a field in the business object for _suppressInvalidity and then override IsValid to accomodate this. Then, you could perhaps provide a method for SaveWithErrors or something like that which would set the flag, do a base.Save(), and then change the _suppressInvalidity back to false.

I'm sure others have had a need for it and have solved it with more rigor, though - so I'm sure there are potentially better ideas than that.

 

 

MadGerbil replied on Friday, September 05, 2008

I found I could override the Save in the base class and exclude the check for IsValid.

For me, the check for IsValid comes in to decide which table to save the records to so that I can have a "working" table and a "live" table for records.  This way the valid collection can save itself to the proper location and the invalid collection saves itself to the other location.

I override it like this:

 

public override AgencyImports Save()

{

AgencyImports result;

if (IsDirty)

result = (AgencyImports)DataPortal.Update(this);

else

result = (AgencyImports)this;

OnSaved(result);

return result;

}

ajj3085 replied on Friday, September 05, 2008

The problem is you're back to the previous behavior where running in a non-remoting scenario you need to have your UI manually clone the object. 

It sounds like your child BO's should decide based on some logic to which table to save.  Again, a warning can be used to communicate with the user.

ajj3085 replied on Friday, September 05, 2008

Your rules should be warnings.  If you need to actually enforce the rules, that sounds like another use case, maybe an approval use case or something?

Copyright (c) Marimer LLC