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

Context Tracking

3 Answers 122 Views
Development (API, general questions)
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Oliver Cox
Top achievements
Rank 1
Oliver Cox asked on 03 Jun 2010, 11:55 AM
Hi,

I downloaded the Silberlight Data Services example and begun to put together my own example but have encountered two issues:

1. When editing a record the error below is thrown when calling context.AddToEntities(entity) method.
    "The context is already tracking the entity."
2. When adding a new entity and moving from one cell to the next the error below is thrown when calling UpdateObject(entity)
    "The context is not currently tracking the entity."

Now presumably I am doing someting wrong here or not accounting for some difference in the versions used in the example. Howver, my real question is how do I test if an entity is already added to the context? Is there for instance any way of testing for context.Entities.Conatins(entity)?

Any help would be greatly appreciated.

Thanks

Oliver

3 Answers, 1 is accepted

Sort by
0
PetarP
Telerik team
answered on 03 Jun 2010, 04:11 PM
Hi Oliver Cox,

You can use the TryGetEntity. If that method does not return anything then the entity is not being tracked and needs to be added. If however the method returns an entity then you will have call the update method rather than add it again since the entity is already being tracked by the context.

Best wishes,
Petar
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
0
Iky
Top achievements
Rank 1
answered on 30 Jan 2015, 01:14 AM
Hi, i can't seem to find any documentation on the TryGetEntity method and I'm not too sure how i would use it. The entity I'm trying to update has a composite key.    

Could you show me a basic usage example or direct me to Documentation?

Thanks
0
Ady
Telerik team
answered on 02 Feb 2015, 10:01 AM
Hello Iky,

The method is called 'TryGetObjectByKey'.
If you tell me what you want to achieve maybe I could provide a more specific solution to your problem.

Regards,
Ady
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
Development (API, general questions)
Asked by
Oliver Cox
Top achievements
Rank 1
Answers by
PetarP
Telerik team
Iky
Top achievements
Rank 1
Ady
Telerik team
Share this question
or