Ticket T1011122
Visible to All Users

Why a child object clears a reference to a parent object when being deleted?

created 4 years ago (modified 4 years ago)

[DevExpress Support Team: CLONED FROM A753: How to restore deleted objects (records)]

Is there some underlying reason why the references to the parent cannot be kept or deleted objects? As far as I can tell, all it would mean is that association join queries would also have to check for GCRecord being null. I'm not sure what the downside of tyhis would be, besides a small slowing down of such queries. Is there something I'm missing here? I understand this was a design decision, but am still confused as to why that cannot be revisited, as it seems keeping references around would buy restoration functionality that is desired by your users.

What are the implications of using Robert Fuch's solution from the Q456052 ticket over the custom IObjectLayer solution Anatol posted in t269498? Anatol's solution relies on an extra Boolean IsSoftDeleted, while RTobert's solution seems to not require anything extra. Are there any downsides to Robert's solution?

Answers approved by DevExpress Support

created 4 years ago

When you call the Delete method, Session does several essential changes on the object to prepare it for deletion. For instance, Session updates links between objects. If the object to be deleted has a reference property decorated with the Association attribute, Session removes that object from the associated collection. When an object is removed from an associated collection, the collection clears the corresponding reference property on the removed object.

The solution that Robert Futch suggested breaks the synchronization of associations and can lead to undesirable consequences. For example, if you delete an object in NestedUnitOfWork and save changes, that object will not be removed from the associated collection in the parent Session.

Currently, XPO does not have an API to restore deleted objects completely. The Deferred Deletion feature is intended for another purpose - avoid conflicts with complex foreign key constraints when deleting multiple objects simultaneously.

I will be very grateful if you tell us about your task, which requires restoring deleted objects. I will try to find the most suitable solution for you.

    Comments (2)

      It turns out my users have decided to make do without object restoration. However, for posterity, I am interested in whether you would recommend Anatol's solution for general use.

      DevExpress Support Team 4 years ago

        Hello Adrian,

        Yes, in a general case we would suggest the Anatol's solution.

        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.