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

Refresh Lazy loaded child entities

1 Answer 359 Views
General Discussions
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Ryan
Top achievements
Rank 1
Ryan asked on 13 Oct 2014, 05:34 AM
Hi,

I am having trouble using the Context.Refresh method on Entities with child lazy-loaded entities. I would like to have a refresh button which causes all objects to be re-loaded from the database (without creating a new context). Currently, if I have a Person object that has multiple Phone Number objects and a single Address object as lazy loaded properties they lazy-load correctly (i.e. the first access causes a database query). However, if I use the Refresh method, all non-database-object properties of the Person object get refreshed from the database (as expected), however subsequent calls to the Phone Number or Address objects do not cause database queries and load the previously loaded versions of these objects (even if there has been updates to these objects in the database). Is there any way for me to mark the child objects of a database object as null or dirty that will cause them to be reloaded on the next call to their getters?

I have had some success with using the Cache.Release method on the parent object (this causes the single object properties to reload from the database), however it does not seem to work at all with any properties that are lists of database objects.

Thanks,

Ryan

1 Answer, 1 is accepted

Sort by
0
Boris Georgiev
Telerik team
answered on 16 Oct 2014, 05:17 PM
Hi Ryan,

I will summarize the outcome of our discussion from the other support thread.

After the context.Refresh() method is called, it will update the object from the context with the data from the database. Next time when the navigation collection property is access, the context will execute a new query to load the objects in the navigation collection from the database.

This works only for navigation collections, For navigation reference property stored in the memory or objects from the collection which is set to variable, it will not works. In this case the OpenAccessContext knows that the object is loaded in the cache and if you didn't explicitly refresh this object, it will be taken from the memory.

We do not recommend using of the Cache.Release() method.

The recommended approach is to dispose the context and use a new one.

Regards,
Boris Georgiev
Telerik
 
OpenAccess ORM is now Telerik Data Access. For more information on the new names, please, check out the Telerik Product Map.
 
Tags
General Discussions
Asked by
Ryan
Top achievements
Rank 1
Answers by
Boris Georgiev
Telerik team
Share this question
or