We migrated to Sitecore 10.1
and Glass Mapper
is upgraded to 5.8.177.0 from 4.3.4.197
.
I noticed the mapping was not working.
I changed the code from
var centreHours = glassContext.GetItem<TradingHoursModel>(Rendering.DataSourceItem.Fields["Centre Hours"].Value);
to
var centreHours = _mvcContext.SitecoreService.GetItem<TradingHoursModel>(Rendering.DataSourceItem.Fields["Centre Hours"].Value);
The model was null and then I added x.LazyDisabled()
var centreHours = _mvcContext.SitecoreService.GetItem<TradingHoursModel>(Rendering.DataSourceItem.Fields["Centre Hours Datasource"].Value, x => x.LazyDisabled());
It started working after x.LazyDisabled()
. Do I need to pass x.LazyDisabled()
in all the .GetItem
method?
Since this is a data source item, I also tried the following code but it didn't work and the model was null.
_mvcContext.GetDataSourceItem<TradingHoursModel>(new GetKnownOptions { Lazy = Glass.Mapper.LazyLoading.Disabled});