Refresh Lazy loaded child entities

2 posts, 0 answers
  1. Ryan
    Ryan avatar
    8 posts
    Member since:
    Jun 2012

    Posted 13 Oct 2014 Link to this post

    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
  2. Boris Georgiev
    Admin
    Boris Georgiev avatar
    190 posts

    Posted 16 Oct 2014 Link to this post

    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.
     
  3. DevCraft banner
Back to Top