Meet us at Sitecore Symposium 2024 and Discover New Ways to Enhance Your Dynamics Experience. Book a Meeting
When we were trying to fetch the child of the datasource item, it was getting a null value for the child. After so much of research, we got to know about the Lazy Loading issue and this has been coming up because of enabling the lazy loading. So, we are trying to turn off the lazy loading by the below method.
[SitecoreChildren(IsLazy = false)]
IEnumerable
The above code is working only if you are using below v5 of glass mapper. But in version 5 or more (v5), the glass mapper has removed this method from here. So we can use an alternative method to turn off lazy loading. Please check the below code.
var datasource = _mvcContext.GetDataSourceItem(new Glass.Mapper.Sc.GetKnownOptions() { Lazy = Glass.Mapper.LazyLoading.Disabled });
We resolved the issue using this method.
These changes are working for us but after some days, we are facing the error as mentioned below and it instructs us to enable lazy loading but but enabling it, we do not get children of the datasource.
Below is the error please check.
Model depth check failed. Model graph too large, enable lazy loading. Type requested:
Sitecore.Data.Items.Itemlocal.Sc.Models.Templates.UserDefined.Main.Entities.Lists.IPublicationType
local.Sc.Models.Templates.UserDefined.Main.Entities.ExperienceAndAnalysis.IExperienceAndAnalysisBase
local.Sc.Models.Templates.Starter.Content.Entities.Services.IService
local.Sc.Models.Templates.Starter.Content.Entities.Professionals.IProfessional
local.Sc.Models.Templates.Starter.Content.Entities.Services.IService
local.Sc.Models.Templates.Starter.Content.Entities.Professionals.IProfessional
local.Sc.Models.Templates.Starter.Content.Entities.Services.IService
local.Sc.Models.Templates.UserDefined.Main.Pages.ICapabilitiesLanding
Description: An unhandled exception occurred.
Exception Details: Glass.Mapper.MapperStackException: Model depth check failed. Model graph too large, enable lazy loading. Type requested:
Sitecore.Data.Items.Itemlocal.Sc.Models.Templates.UserDefined.Main.Entities.Lists.IPublicationType
local.Sc.Models.Templates.UserDefined.Main.Entities.ExperienceAndAnalysis.IExperienceAndAnalysisBase
local.Sc.Models.Templates.Starter.Content.Entities.Services.IService
local.Sc.Models.Templates.Starter.Content.Entities.Professionals.IProfessional
local.Sc.Models.Templates.Starter.Content.Entities.Services.IService
local.Sc.Models.Templates.Starter.Content.Entities.Professionals.IProfessional
local.Sc.Models.Templates.Starter.Content.Entities.Services.IServicew
local.Sc.Models.Templates.UserDefined.Main.Pages.ICapabilitiesLanding
By doing R&D, we got the option which is given in lazy loading “OnlyReferenced”. We applied this option on lazy loading and then the issue was resolved.
var datasource = _mvcContext.GetDataSourceItem<IInterfaceClass>(new Glass.Mapper.Sc.GetKnownOptions() { Lazy = Glass.Mapper.LazyLoading.OnlyReferenced });
This error occurred because lazy loading disables the item nested child and so on till the 8th child comes after the 8th child will not be permitted.
Lazy loading disabled: Lazy loading is disabled for the current model and all referenced Glass models.
Lazy loading Only reference: Lazy loading is disabled for the current model but all referenced model will be lazy loaded.
Unlock 40 hour of
free consultation with
our top experts now!