Test if an object is marked for deletion

8 posts, 1 answers
  1. Christoph
    Christoph avatar
    8 posts
    Member since:
    Mar 2011

    Posted 19 Jan 2012 Link to this post

    Hello

    I am implementing a tracking system. I would like to know what objects are getting inserted or updated in the db.
    I am doing that with the ContextChanges objects. However, when I insert a new object in the context and then delete it from the context, it stills appear in the GetInserts() list. If I try to manipulate it, I receive the following exception.
    "It is not allowed to read or to write an instance marked for deletion."

    The property "ReadAfterDelete" wouldn't help, because if I set it to true I will believe that the object actually get inserted while it is not.
    I know I could try to access a property and catch the exception to know that the object is marked for deletion, but I hope there is a better solution.

    Thank you
  2. TSE
    TSE avatar
    381 posts
    Member since:
    Sep 2008

    Posted 19 Jan 2012 Link to this post

    Hi Christoph,

    I don't know if this is an error or not...  You still performed the "action" insert of object A in the context.  And you also performed the "action" delete of object A in the context.
    So if you consider the Context to be a memory registration of all the changes you performed since the creation of the context what you see is correct.
    In respect to your tracking system, you should just provide that if an object is present in the "GetDeletes" lists it takes precedence over any other list.

    Regards

    Henrik
  3. DevCraft banner
  4. Christoph
    Christoph avatar
    8 posts
    Member since:
    Mar 2011

    Posted 19 Jan 2012 Link to this post

    Hello Henrik

    Thank you for your reply.

    What is strange is that my object does not appear in the GetDeletes() result.
  5. Answer
    Ralph Waldenmaier
    Admin
    Ralph Waldenmaier avatar
    202 posts

    Posted 19 Jan 2012 Link to this post

    Hi Christoph,
    @Henrik: Thank you for the valuable input.

    @Christoph: As Henrik mentioned, the information provided by the GetDeletes() method is correct, since there was only a in memory operation involved in your case. But the result from the GetInserts() method is not correct and is a bug, which I would like to thank you for pointing out. Please find your Telerik points updated for this.
    To your question regarding your tracking system. You can use our ITracking Interface to get notified if an object is modified. With this you can build your own logic to meet your requirements.

    I hope this information is helpful for you. Feel free to ask if you have any other question.

    All the best,
    Ralph
    the Telerik team

    SP1 for Q3’11 of Telerik OpenAccess ORM is available for download

  6. Christoph
    Christoph avatar
    8 posts
    Member since:
    Mar 2011

    Posted 19 Jan 2012 Link to this post

    Hello Ralph

    thank you for the informations.
    So if I understand well, neither GetInserts nor GetDeletes should give a result if an object is inserted then removed from the context without saving it.

    I should be able to implement my solution now, thanks
    Regards
  7. Shawn Krivjansky
    Shawn Krivjansky avatar
    86 posts
    Member since:
    Jan 2010

    Posted 13 Apr 2012 Link to this post

    I'm using the newer domain context.
    I need to be able to turn off this behavior (disallowing reads on objects marked for deletion).

    Where does one set this property "ReadAfterDelete" given one is using the domain context??

    A search of Google showed the release notes for OpenAccess in 2011 Q1 making mention of adding this to the backend config/runtime settings
    http://www.telerik.com/products/orm/whats-new/release-history/q1-2011-sp1-version-2011-1-411.aspx
    , but I cannot find any UI for this property in the current 2012 Q1 version.

    How does one access this property?
  8. Shawn Krivjansky
    Shawn Krivjansky avatar
    86 posts
    Member since:
    Jan 2010

    Posted 13 Apr 2012 Link to this post

    Nevermind.
    I thought there would be a setting in the UI for the backend configuration for this, but I guess not.  After playing around in the code I came across:

    backend.Runtime.AllowReadAfterDelete

    ...which is what I was looking for, just didn't think I would need to add code for it when there is a UI.

     

  9. Ralph Waldenmaier
    Admin
    Ralph Waldenmaier avatar
    202 posts

    Posted 16 Apr 2012 Link to this post

    Hi Shawn Krivjansky,

    I'm glad that you have managed to enable this feature. Nevertheless, I have added this point regarding the UI settings to our backlog.

    Feel free to ask if you have any other question.

    All the best,
    Ralph
    the Telerik team
    Telerik OpenAccess ORM Q1 2012 release is here! Check out what's new or download a free trial >>
Back to Top
DevCraft banner