Lazy load

6 posts, 0 answers
  1. illya
    illya avatar
    5 posts
    Member since:
    Aug 2011

    Posted 13 Jun 2013 Link to this post

    Hi,

    I would like to disable lazy load for entities.
    I know that in EF it is possible to do that (dataContext.ContextOptions.LazyLoadingEnabled = false)

    Is it possible in OA? I know that it is possible to setup for each of relation (WithLoadBehavior(Telerik.OpenAccess.LoadBehavior.Lazy ), but I do not want to do that for each of relation.

    Thanks.
    Illia

  2. Boris Georgiev
    Admin
    Boris Georgiev avatar
    190 posts

    Posted 17 Jun 2013 Link to this post

    Hi Illya, 

    I am afraid that at the moment Telerik OpenAccess ORM does not provide a "disable lazy loading" option.

    I have created a new feature request in our Ideas and Feedback Portal. You are invited to vote for it and promote it. More votes will increase its priority in our backlog. If you feel that you would like to add something to the description - just post a comment to the item.

    Please excuse us for the inconvenienced caused. 

    Regards,
    Boris Georgiev
    Telerik
    OpenAccess ORM Q2 2013 brings you a more powerful code generation and a unique Bulk Operations support with LINQ syntax. Check out the list of new functionality and improvements shipped with this release.
  3. DevCraft banner
  4. Gary
    Gary avatar
    28 posts
    Member since:
    Jun 2015

    Posted 21 Aug 2015 in reply to Boris Georgiev Link to this post

    Any movement on this? Perhaps it's ​available now (the O.P. is pretty old)? I really need this to be there. If not what is the work around. The problem I am having is I have a class that maps ORM Models to other Domain models ... by iterating through each of the ORM Model's properties and mapping the contents to the new Domain Model. Of course as soon as any navigation property is queried, it is "lazily" loaded which is resulting in, as you could probably guess, Stackoverflow exceptions as the ORM Models begin to re curse upon themselves. 

     

    Perhaps there's a better way to accomplish what I am attempting to do?

  5. Yavor Slavchev
    Admin
    Yavor Slavchev avatar
    22 posts

    Posted 25 Aug 2015 Link to this post

    Hello Gary,
    Thank you for contacting us.
     
    Does in mean that you are not interest in the navigation properties when you iterate through a certain ORM model? If so, the solution is to skip these type of properties during the iteration by inspecting the property type to be PersistenceCapable or IList<PersistenceCapable>. Note that when you are checking the navigation property type, you should use a reflection to get the type properties as property descriptors and then get the type property from there, otherwise, you will get into the same lazy loading issue and the overflow exception.
    If you want to iterate through the navigation properties, then you should implement a method that keeps track of already iterated objects and skip these objects during the iteration. This will avoid the stack overflow issue that you are currently experiencing.

    I hope this helps. Do get back to us in case you have further questions.

    Regards,
    Yavor Slavchev
    Telerik
     
    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
  6. Gary
    Gary avatar
    28 posts
    Member since:
    Jun 2015

    Posted 25 Aug 2015 in reply to Yavor Slavchev Link to this post

    Thank you very much for the response.

    The ​scenario is that some navigation properties may already be loaded due to the Fetch Strategy (although I am having some difficulty with this as well [See Post] ). I want to ​iterate through the values of any PRE-loaded navigation properties, but skip any properties that have been ​NOT yet been loaded. I have extended the models by adding a member (in a partial class) that checks the private variable associated with the navigation property to see if it has been populated yet or not​; hopefully, by-passing the "Lazy loading" logic. 

     

  7. Yavor Slavchev
    Admin
    Yavor Slavchev avatar
    22 posts

    Posted 26 Aug 2015 Link to this post

    Hi again,

    In order to determine whether a property in the entity is loaded or not, you can use something like this:
    var context = new FluentModel();
    var product = context.Products.First();
     
    // Should be false
    var isLoaded1 = (context.GetState(product, "OrderDetails") & Telerik.OpenAccess.ObjectState.MaskLoaded) != 0;
    var orders = product.OrderDetails;
    // Should be true
    var isLoaded2 = (context.GetState(product, "OrderDetails") & Telerik.OpenAccess.ObjectState.MaskLoaded) != 0;
    The code snippet is based on the Northwind database where a product is related to multiple order details.
    The navigation property OrderDetails is not loaded until it is accessed. The same is valid if this property is loaded by lazy loading. In this case the check will return true.

    I hope this will help you resolving the issue.

    Regards,
    Yavor Slavchev
    Telerik
     
    Check out the latest announcement about Telerik Data Access vNext as a powerful framework able to solve core development problems.
Back to Top
DevCraft banner