0

Using Sitecore 10.2 and Glass Mapper 5.8.180

After upgrade from Sitecore 8.2 and switching to above mentioned version of Glass Mapper our code stopped loading collection references. I am aware that in Glass Mapper now the lazy loading is turned on by default and I want to keep this setting.

Problem is with follows:

Having

[SitecoreType(TemplateId = "{...}", AutoMap = true)]
public interface IStatementContainer
{
    IEnumerable<Statement> Statements { get; set; }
}

public class StatementContainer : IStatementContainer
{
    public virtual IEnumerable<Statement> Statements { get; set; }
}

The following code

_mvcContext.SitecoreService.GetItem<StatementContainer>(datasource)

does not work properly. The Statements are empty.

Empty statements

For following code

_mvcContext.SitecoreService.GetItem<IStatementContainer>(datasource)

the Statements are being loaded properly.

Statements are loaded

Could you explain me the difference in behavior?

Our legacy code contains a lot of usages of concrete types rather than interfaces, changing all of them would be difficult.

Wojtek
  • 135
  • 1
  • 1
  • 9
  • Glass Mapper created proxy classes around original type in newer versions. That's why they cannot be cast to original type class but interfaces can be used. – Marek Musielak Sep 08 '22 at 11:55

0 Answers0