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

Lazy load

5 Answers 204 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.
illya
Top achievements
Rank 1
illya asked on 13 Jun 2013, 01:07 PM

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

5 Answers, 1 is accepted

Sort by
0
Boris Georgiev
Telerik team
answered on 17 Jun 2013, 02:08 PM
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.
0
Gary
Top achievements
Rank 1
answered on 21 Aug 2015, 03:22 PM

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?

0
Yavor Slavchev
Telerik team
answered on 25 Aug 2015, 06:13 AM
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.
0
Gary
Top achievements
Rank 1
answered on 25 Aug 2015, 03:18 PM

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. 

 

0
Yavor Slavchev
Telerik team
answered on 26 Aug 2015, 01:49 PM
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.
Tags
Development (API, general questions)
Asked by
illya
Top achievements
Rank 1
Answers by
Boris Georgiev
Telerik team
Gary
Top achievements
Rank 1
Yavor Slavchev
Telerik team
Share this question
or