This is a migrated thread and some comments may be shown as answers.

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

3 Answers 21 Views
Getting Started
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Wolfgang
Top achievements
Rank 1
Wolfgang asked on 05 Jun 2013, 11:09 AM
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

3 Answers, 1 is accepted

Sort by
0
Boris Georgiev
Telerik team
answered on 05 Jun 2013, 04:36 PM
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.
0
Wolfgang
Top achievements
Rank 1
answered on 06 Jun 2013, 07:44 AM
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
0
Ady
Telerik team
answered on 10 Jun 2013, 01:53 PM
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.
Tags
Getting Started
Asked by
Wolfgang
Top achievements
Rank 1
Answers by
Boris Georgiev
Telerik team
Wolfgang
Top achievements
Rank 1
Ady
Telerik team
Share this question
or