Ticket T311314
Visible to All Users

Child Object Save Forces a Save in Parent Object

created 9 years ago

Hi

I have run into the following problem and would like some suggestions.  We have an application with Invoices and InvoiceItems (a one to many relationship).  On save of the Invoice our system sends out an automated email to the recipient with the invoice attached.  That works perfectly.  The problem we have though is two-fold:

  1. Upon saving a child item in non-inline edit, it forces a save in the invoice object as well which triggers the sending of the mail (a big problem as the recipient now receives a mail for each item as it is being entered)
  2. To solve this problem we switched to inline edit mode which works as expected.  The invoice object is only saved on saving of the invoice, not the child records.  The problem is that the New button still appears to allow the user to create a new record in detail view.  I have hidden the edit button which was simple enough with the following code in a ViewController

if (View is ListView && View.ObjectTypeInfo.Type == typeof(InvoiceItem))
            {
                Frame.GetController<DevExpress.ExpressApp.Web.SystemModule.ListViewController>().EditAction.Active.SetItemValue("myReason", false);

}

But there is no way to hide the New button in the same manner because it hides the inline new as well.

So now my questions

  1. Is there now a better way to accomplish the hiding of the New button than in the very old post Q2781232) Is the better solution perhaps to try stop the child record forcing a save on the parent record in detail view?  If so how would one do that?

Answers approved by DevExpress Support

created 9 years ago (modified 9 years ago)

Hello Gavin,

1. Yes, there is a newer way to accomplish this task - see ActionControlsSiteController.CustomizeContainerActions Event.

  1. If this is an aggregated collection, you can check the Session type before sending email:
C#
protected override void OnSaved() { base.OnSaved(); if (!(Session is NestedUnitOfWork)) { // send email } }

Otherwise, you can enable property modification tracking and send an email only when a certain master object's properties have been changed - see get "changed" state of xpobject and it´s fields.

In addition, in version 15.2, we will introduce a new way of linking a master object to new detail objects, and the master object's OnSaved method will not be called in this mode until the master object is saved.

    Show previous comments (4)
    Anatol (DevExpress) 9 years ago

      This button belongs to the grid control and is not associated with any XAF action. To add a new row in code, use the ASPxGridView.AddNewRow method. See an example here: Create a new inline.
      Refer to the Adding and Deleting Records topic for additional information.

      D D
      Digg-IT Technologies (Dino) 9 years ago

        Thanks.  Much appreciated

        Anatol (DevExpress) 9 years ago

          You are always welcome!

          Disclaimer: The information provided on DevExpress.com and affiliated web properties (including the DevExpress Support Center) is provided "as is" without warranty of any kind. Developer Express Inc disclaims all warranties, either express or implied, including the warranties of merchantability and fitness for a particular purpose. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.

          Confidential Information: Developer Express Inc does not wish to receive, will not act to procure, nor will it solicit, confidential or proprietary materials and information from you through the DevExpress Support Center or its web properties. Any and all materials or information divulged during chats, email communications, online discussions, Support Center tickets, or made available to Developer Express Inc in any manner will be deemed NOT to be confidential by Developer Express Inc. Please refer to the DevExpress.com Website Terms of Use for more information in this regard.