Is it possible to ask wether an object is marked for deletion?

4 posts, 0 answers
  1. Wolfgang
    Wolfgang avatar
    98 posts
    Member since:
    Oct 2012

    Posted 05 Jun 2013 Link to this post

    Hi,

    If an object is accessed which is marked for deletion, telerik will throw an InvalidOperationException.

    This is not bad, but... is there a way to ask if an object is marked for deletion?

    I want to remove items from a list. If something else has marked the same items to be deleted, the exception and error handling seems to slow the progress down.

    So is there somewhere something like an Extension method object.IsMarkedForDeletion() ? 

    Best regards
    Wolfgang
  2. Boris Georgiev
    Admin
    Boris Georgiev avatar
    190 posts

    Posted 05 Jun 2013 Link to this post

    Hello Wolfgang, 

    You can use the GetState() method provided by OpenAccessContext. It will return the state of an object which is passed as parameter to the method.

    Here is a sample how to use this method:
    1.Telerik.OpenAccess.ObjectState entityState = context.GetState(entity);
    2. 
    3.if (entityState != Telerik.OpenAccess.ObjectState.Deleted)
    4.{
    5....
    6.}

    I hope that helps.

    Regards,
    Boris Georgiev
    Telerik
    OpenAccess Samples Kit boasts 50+ sample applications providing diverse real-life business solutions. Click to read more and see OpenAccess ORM in action.
  3. DevCraft banner
  4. Wolfgang
    Wolfgang avatar
    98 posts
    Member since:
    Oct 2012

    Posted 06 Jun 2013 Link to this post

    Thanks Boris,

    Is it also available from Old API?

    ATM I used your info and the workaround:
    Telerik.OpenAccess.SPI.IExtendedObjectScope objectScope = persistentObject.ObjectScope as Telerik.OpenAccess.SPI.IExtendedObjectScope;

    which could also be shortened to

    if( Telerik.OpenAccess.ObjectState.Deleted == (persistentObject.ObjectScope as Telerik.OpenAccess.SPI.IExtendedObjectScope).GetState(persistentObject))

    which then looks a bit irritating.

    Best regards
    Wolfgang
  5. Ady
    Admin
    Ady avatar
    589 posts

    Posted 10 Jun 2013 Link to this post

    Hi Wolfgang,

      The 'GetState' method is defined on the IObjectScope. You do not need to cast it to 'IExtendedObjectScope'. Simply call 'scope.GetState(entity)' 

    Regards,

    Ady
    Telerik
    OpenAccess Samples Kit boasts 50+ sample applications providing diverse real-life business solutions. Click to read more and see OpenAccess ORM in action.
Back to Top