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
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
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?
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
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.
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 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