0

We are upgrading GlassMapper to V5 and installed Glass.Mapper.Sc.90. I am doing all the changes mentioned in http://www.glass.lu/Mapper/documentation/Upgrade-ToV5.html link one by one. Now, i am working on Lazy.

I have disabled Lazy on Model and trying to implement on services when a model is requested. So far the below is working fine _mvcContext.**GetDataSourceItem**<ITest>(x => x.LazyDisabled());

But when trying the below, i am getting an error.

_mvcContext.**GetContextItem**<IPageBase>(x => x.LazyDisabled()); When I mouse hover on x => x.LazyDisabled(), I am seeing Cannot convert lambda expression to type 'GetKnownOptions' because it is not a delegate type

also the webpage errors out with below stack trace.

Model depth check failed. Model graph too large, enable lazy loading. Type requested: Test.Models.ISitecoreItemTest.Models.ISitecoreItem Test.Models.ISitecoreItem Test.Models.ISitecoreItem Test.Models.ISitecoreItem Test.Models.ISitecoreItem Test.Models.ISitecoreItem Test.Models.ISitecoreItem Test.Models.Common.IPageBase

What should I do here? Thoughts?

my GlassMapperScCustom.cs looks like below

`public static IDependencyResolver CreateResolver(){ var config = new Glass.Mapper.Sc.Config();

        //Needed to avoid Model-too - deep exception
        config.OnDemandMappingEnabled = true;
        config.Cache.AlwaysOn = true;

        //config.EnableLazyLoadingForCachableModels = true;             // Only for V4. Deprecated in V5
        var dependencyResolver = new DependencyResolver(config);
        // add any changes to the standard resolver here
        dependencyResolver.ObjectConstructionFactory.Remove<ItemVersionCountByRevisionTask>();
        //dependencyResolver.ObjectConstructionFactory.Remove<ModelDepthCheck>(); // **This is not working.**
        
        return dependencyResolver;
    }`

Thanks in advance.

5
  • I have given the same answer here. You can refer. sitecore.stackexchange.com/questions/30410/… Dec 9, 2021 at 11:20
  • @HimmatSinghDulawat: Thanks for writing. I already saw the above post. It clearly explains the generic class where we enable/disable Lazy for all the GetItem. But I don't want lazy to get disabled/enabled for all GetItem. So I am trying to write it individually on each call. Dec 10, 2021 at 2:07
  • also added GlassMapperScCustom.cs if there is something i am missing. Dec 10, 2021 at 2:18
  • Try this if you dont want ofr all GetItem: var dataSource = _mvcContext.GetDataSourceItem<IPageBase>(new GetKnownOptions { Lazy = Glass.Mapper.LazyLoading.Disabled}); Dec 10, 2021 at 5:28
  • 1
    Thanks @HimmatSinghDulawat i see that My solution has t4 templates in TDS, where the Cacheable= true is set for all templates. We have to disable it and everything started working fine like using new GetKnownOptions { Lazy = Glass.Mapper.LazyLoading.Disabled} on ContextItem Dec 10, 2021 at 12:49

1 Answer 1

0

If you look at the GetContextItem method, you'll see it accepts GetKnownOptions as a parameter now.

Then you can just do something like that:

_mvcContext.**GetContextItem**<IPageBase>(new GetKnownOptions{Lazy = LazyLoading.Disabled});

I hope it helps you.

3
  • Thanks for writing. I tried your code sample above but it didn't work. Although the above code is accepted and compiles clean, I still have the same error on the same line (can confirm this by having a breakpoint) Dec 10, 2021 at 2:09
  • also added GlassMapperScCustom.cs if there is something i am missing. Dec 10, 2021 at 2:18
  • 1
    Thanks @MiguelMinoldo, I see that My solution has t4 templates in TDS, where the Cacheable= true is set for all templates. We have to disable/remove it and everything started working fine after using new GetKnownOptions { Lazy = Glass.Mapper.LazyLoading.Disabled} on ContextItem Dec 10, 2021 at 12:50

Not the answer you're looking for? Browse other questions tagged or ask your own question.