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

Lazy-Loading

2 Answers 73 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.
Thorsten
Top achievements
Rank 1
Thorsten asked on 03 Feb 2013, 12:06 AM
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 Answers, 1 is accepted

Sort by
0
Thorsten
Top achievements
Rank 1
answered on 03 Feb 2013, 07:14 PM
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 );
         ....
    }
}
0
Damyan Bogoev
Telerik team
answered on 06 Feb 2013, 08:00 AM
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.
Tags
Development (API, general questions)
Asked by
Thorsten
Top achievements
Rank 1
Answers by
Thorsten
Top achievements
Rank 1
Damyan Bogoev
Telerik team
Share this question
or