Lazy-Loading

3 posts, 0 answers
  1. Thorsten
    Thorsten avatar
    26 posts
    Member since:
    Apr 2010

    Posted 02 Feb 2013 Link to this post

    Hi,

    i've got a question regarding the way openaccess handles lazy loading:

    Lets say i've got the following entities:
    public class Customer
    {
       string Name {get; set;}
       IList<RentalOrders> RentalOrders {get;set;}
    }
    public class RentalOrder
    {
    ...
    }

    and the following method:
    public void WriteCustomer( Customer customer )
    {
       ...
    }

    I'd like to write out the currently available properties (including the navigation properties, if loaded) of the customer entity without triggering any lazy-load calls.
    But when the method gets called, i know nothing about the customer's origin.
    Hence i don't know if the Property "RentalOrders" has been included via a fetchstrategy/include or not.

    Is there a way to detect if navigation property X for entity Y on instance Z has been loaded or not ?

    So far what i've come up with, doesn't really get me where i want to be:
    var mgr = customer.OpenAccessEnhancedGetPersistenceManager();
    if (mgr != null)
    {
          var scope = mgr.getUserObject() as IExtendedObjectScope;
          if (scope != null)
          {
                 var omg = new ArrayList(1);
                 omg.Add(customer);
                 scope.CreateDetachedCopies( omg, null );
                 customer= omg[0];
          }
    }
    The snippet above avoids any Lazy-Load call, but i loose any previously loaded navigation property.

    Thanks in advance.

    Kind regards,

    Thorsten Klingert


  2. Thorsten
    Thorsten avatar
    26 posts
    Member since:
    Apr 2010

    Posted 03 Feb 2013 Link to this post

    Hi again,

    this one can be closed, i've found a solution for it:

    PersistenceCapable entity
    IPersistenceManager mgr = entity.OpenAccessEnhancedGetPersistenceManager( );
    if (mgr != null)
    {
        var scope = mgr.getUserObject( ) as IObjectScope;
        if (scope != null)
        {
             var notYetLoadedMembers = scope.GetMemberNames( entity, ObjectState.NotLoaded );
             ....
        }
    }
  3. DevCraft banner
  4. Damyan Bogoev
    Admin
    Damyan Bogoev avatar
    581 posts

    Posted 06 Feb 2013 Link to this post

    Hello Thorsten,

    I am glad to see that you have managed to find a solution to this problem.

    Do not hesitate to contact us if you face further trouble.


    All the best,
    Damyan Bogoev
    the Telerik team
    Q3'12 SP1 of OpenAccess ORM packs Multi-Table Entities mapping support. Check it out.
Back to Top