Im having a problem with Glass Mapper, mapping/casting an item to a custom model.
The Model with the complextype property (snippet):
[SitecoreType(TemplateId = Templates.IDString, AutoMap = true)]
public class EmployeeModel
{
///other propertes hidden
[SitecoreChildren(IsLazy = true)]
[SitecoreField(FieldId = Templates.Items.Office.Fields.BusinessOfficeString)]
public virtual ItemViewModel Office { get; set; }
}
The ItemViewModel:
[SitecoreType(AutoMap =true)]
public class ItemViewModel
{
public virtual ID Id { get; set; }
public virtual string Template { get; set; }
public virtual string Name { get; set; }
public virtual string Url { get; set; }
public virtual Dictionary<string, IFeatureModel> Features { get; set; }
}
To create this EmployeeModel im casting an Sitecore Item to this model:
var featureModel = _sitecoreService.Cast<EmployeeModel>(item);
But this call is throwing an error:
The type Foundation.Macaw.Modeling.Models.ViewModels.ItemViewModel does not contain any generic arguments
I think this is caused by the [SitecoreChildren(IsLazy = true)]
because when i remove this line it works. However without that line an stackoverflow can be caused since the OfficeModel has a reference to Employee...
When casting directly to an ItemViewModel the same item works like a charm:
var featureModel = _sitecoreService.Cast<EmployeeModel>(item);
Any one knows what could solve my problem?
FYI: im using Sitecore 9 Update 1 and glassmapper 4.5.04
Tnx!