1

I'm trying to get children of a specific template under an item using:

    [SitecoreQuery("./*[@@templateid='{051E9E07-F488-41EA-A87E-0A92EA32B86B}']", IsRelative = true)]
    public virtual IEnumerable<TopMenuCategory> TopMenuCategories { get; set; }

However this seems to be returning an error:

The type BrightHorizonsCorp.Models.Navigation.ItemClasses.TopMenuCategory on BrightHorizonsCorp.Models.Navigation.ItemClasses.TopMenuCategory.ID is not supported by SitecoreIdMapper

My TopMenuCategory class looks like this:

public class TopMenuCategory
{
    [SitecoreId]
    public virtual Guid Id { get; set; }
    [SitecoreItem]
    public virtual Item SitecoreItem { get; set; }

    public virtual string Title { get; set; }
    public virtual string Drawer_Title { get; set; }
    public virtual bool Hide_on_Mobile { get; set; }

    [SitecoreQuery("./*[@@templateid='{606CB1C6-35FB-4FFE-8EA6-08EE7D5D46D1}']", IsRelative = true)]
    public virtual IEnumerable<MenuCategory> Categories { get; set; }
    [SitecoreQuery("./*[@@templateid='{57FDD488-21C1-4974-80B3-E507EBB7B27A}']", IsRelative = true)]
    public virtual IEnumerable<MenuLink> Links { get; set; }
    [SitecoreQuery("./*[@@templateid='{39C5DEE0-4CBE-4D7E-B87A-8F8115B60311}']", IsRelative = true)]
    public virtual IEnumerable<MenuLinkWithImage> ImageLinks { get; set; }

    public ShortID ShortId
    {
        get { return SitecoreItem.ID.ToShortID(); }
    }

    public string ID
    {
        get { return Id.ToString().Replace("{", "").Replace("}", ""); }
    }
}

I have two questions:

  1. What is the cause of this error? How does one resolve it?
  2. Is there any alternative to this, where I don't have to hardcode the item ID in the data attribute?
1
  • I would recommend creating a second question for your #2 above, since it's unrelated to the error you received. Dec 5, 2018 at 2:25

1 Answer 1

0

After resolving other errors and trying trial and error, I found the problem was:

public string ID
{
    get { return Id.ToString().Replace("{", "").Replace("}", ""); }
}

When I rename this property to something other than "ID", the error does not occur, however it does if I leave it like this. Glass must have been confused or something. I'm still interested in an alternative that doesn't require hardcoding the item ID, if anyone has any ideas.

2
  • What are you using this property for, and why do you need it (since you already have the Id property)? Also, you can simplify the code by simply returning Id.ToString("D"). Dec 5, 2018 at 2:27
  • It is an old field I was using before we implemented Glass. It doesn't need to be there as it isn't used anymore. Nice to know about the ToString call.
    – Paul
    Dec 5, 2018 at 17:42

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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