CSLA .NET

From Rockford Lhotka's Expert C# 2005 and VB 2005 Business Objects books

Welcome to CSLA .NET Sign in | Join | Help
in Search

Save a collection of invalid objects through the dataportal.

Last post 09-05-2008, 2:58 PM by ajj3085. 4 replies.
Sort Posts: Previous Next
  •  09-05-2008, 1:30 PM 25974

    Save a collection of invalid objects through the dataportal.

    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.

     

     


    <:3 )~~
  •  09-05-2008, 1:38 PM 25975 in reply to 25974

    Re: Save a collection of invalid objects through the dataportal.

    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.

     

     

  •  09-05-2008, 1:42 PM 25976 in reply to 25974

    Re: Save a collection of invalid objects through the dataportal.

    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?
  •  09-05-2008, 1:43 PM 25977 in reply to 25975

    Re: Save a collection of invalid objects through the dataportal.

    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;

    }


    <:3 )~~
  •  09-05-2008, 2:58 PM 25980 in reply to 25977

    Re: Save a collection of invalid objects through the dataportal.

    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.
View as RSS news feed in XML

Please contact Magenic for your .NET consulting and CSLA .NET mentoring needs.
Please consider making a donation to help support the ongoing development of CSLA .NET.

Make donation through PayPal - it's fast, free and secure!
Why donate?
Powered by Community Server, by Telligent Systems