I can’t understand why Glass Mapper cannot distinguish an object correctly as described here.
I have the following classes
public class BC
{
[SitecoreId]
public virtual ID Id { get; set; }
}
public class WB : BC
{
[SitecoreField(FieldName = "P1")]
public virtual Glass.Mapper.Sc.Fields.Link P1 { get; set; }
}
[SitecoreType(TemplateId = "{XXX}", AutoMap = true, EnforceTemplate = SitecoreEnforceTemplate.Template)]
public class AAA : WB
{
public virtual string AAAP1 { get; set; }
public virtual DateTime AAAP2 { get; set; }
}
[SitecoreType(TemplateId = "{VVV}", AutoMap = true, EnforceTemplate = SitecoreEnforceTemplate.Template)]
public class BBB : WB
{
public virtual string BBBp1 { get; set; }
public virtual DateTime BBBp2 { get; set; }
}
[SitecoreType(TemplateId = "{YYY}", AutoMap = true)]
public class RazorRenderClass: BC
{
[SitecoreChildren(InferType = true)]
public virtual IEnumerable<WB> Children { get; set; }
[SitecoreChildren(InferType = true)]
public virtual IEnumerable<AAA> AAACh { get; set; }
[SitecoreChildren(InferType = true)]
public virtual IEnumerable<BBB> BBBCh { get; set; }
}
in razor mode I cannot get AAA or BBB objects if I use the Children property,
@foreach (var child in Model.Children)
{
if (child is BBB)
{
var news = child as BBB;
<li>
11
</li>
}
else if (child is AAA)
{
var evt = child as AAA;
<li>
222
</li>
}
}
More interestingly, if I use the BBBCh or AAACh property call in cshtml, I can see (when debugging) that the Children property contains the correct elements (object), but if I try to get any element from the Children property, eg
var detailWidget = Model.Children.FirstOrDefault();
it will be passed to the WB class. What can I do about it?
source
share