Exception using SitecoreQuery to map children of a specific template

256 views
Skip to first unread message

Kyle Heon

unread,
Feb 24, 2014, 3:38:35 PM2/24/14
to glasssite...@googlegroups.com
I used Tutorial 7 as a guide for this. I have the Sitecore Query syntax correctly working in the XPath Builder but when I add to my property and navigate to the page where I use this model I get the following error:

Could not find a data mapper to handle property AbstractPropertyConfiguration Property: Applications Type: Data.Models.Sitecore.Templates.UserDefined.Pages.SolutionPage Assembly: Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

Description: An unhandled exception occurred during the execution of the current web request. Please review the stack trace for more information about the error and where it originated in the code. 

Exception Details: Glass.Mapper.MapperException: Could not find a data mapper to handle property AbstractPropertyConfiguration Property: Applications Type: Data.Models.Sitecore.Templates.UserDefined.Pages.SolutionPage Assembly: Data, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null

My model class looks like this:

public partial class SolutionPage
{
    [SitecoreField(FieldName = ISectionPageConstants.PageAssetFieldName)]
    public MediaFile PageAssetMedia { get; set; }

    [SitecoreQuery("./*/*", IsRelative = true)]
    public IEnumerable<ICategoryPage> Categories { get; set; }

    [SitecoreQuery("./*/*[@@templatename='ApplicationPage']", IsRelative = true)]
    public List<ApplicationPage> Applications { get; set; }

    [SitecoreQuery("./*/*[@@templatename='ProductLinePage']", IsRelative = true)]
    public List<ProductLinePage> ProductLines { get; set; }
}

View code looks like this:

<h3>Applications</h3>
<ul>
    @foreach (var item in Model.Applications)
    {
        <li>@item.NavigationTitle</li>
    }
</ul> 

Anyone have some advise on what I'm doing wrong? Thanks!

-K 

Michael Edwards

unread,
Feb 25, 2014, 4:44:29 AM2/25/14
to glasssite...@googlegroups.com
Your return types are List<T> and not IEnumerable<T>, change them to IEnumerable<T>.

Mike


--
You received this message because you are subscribed to the Google Groups "Glass.Sitecore.Mapper" group.
To unsubscribe from this group and stop receiving emails from it, send an email to glasssitecorema...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Kyle Heon

unread,
Feb 25, 2014, 7:20:05 AM2/25/14
to glasssite...@googlegroups.com, mikeed...@googlemail.com
Mike,

Funny you suggested that, I'd already made that change after posting this and still couldn't get it working. I tried with the interface and the concrete implementation within the IEnumerable.

I did manage to get this working but not via the attribute. This is working for me, not sure why the attribute won't but at least I have the data I need:

public partial interface ISolutionPage
{
    IEnumerable<IApplicationPage> Applications { get; set; }
    IEnumerable<IProductLinePage> ProductLines { get; set; }
}

public partial class SolutionPage
{
    [SitecoreField(FieldName = ISectionPageConstants.PageAssetFieldName)]
    public MediaFile PageAssetMedia { get; set; }

    [SitecoreQuery("./*/*", IsRelative = true)]
    public IEnumerable<ICategoryPage> Categories { get; set; }

    public IEnumerable<IApplicationPage> Applications { get; set; }

    public IEnumerable<IProductLinePage> ProductLines { get; set; }

    public SolutionPage()
    {
        var context = new SitecoreContext();

        Applications =
            context.QueryRelative<IApplicationPage>("./*/*[@@templateid='{533670B4-BA56-4AD9-9840-7E34E1E0ED94}']",
                                                    true, true);

        ProductLines =
            context.QueryRelative<IProductLinePage>("./*/*[@@templateid='{F183AD73-9DE6-4035-99EE-446166D94A6D}']",
                                                    true, true);
    }
}

Thanks! 

Michael Edwards

unread,
Feb 25, 2014, 1:15:19 PM2/25/14
to Kyle Heon, glasssite...@googlegroups.com
So the Categories property works ok but the other two don't?

You need to ensure also that you mark your properties as virtual.

Mike

Kyle Heon

unread,
Feb 26, 2014, 7:23:47 AM2/26/14
to glasssite...@googlegroups.com, Kyle Heon, mikeed...@googlemail.com
Aha! I bet it was the missing virtual because this is working for me now:

public partial interface ISolutionPage
{
    [SitecoreQuery("./*/*[@@templateid='{533670B4-BA56-4AD9-9840-7E34E1E0ED94}']", InferType = true, IsLazy = true,
        IsRelative = true)]
    IEnumerable<IApplicationPage> Applications { get; set; }

    [SitecoreQuery("./*/*[@@templateid='{F183AD73-9DE6-4035-99EE-446166D94A6D}']", InferType = true, IsLazy = true,
        IsRelative = true)]
    IEnumerable<IProductLinePage> ProductLines { get; set; }
}


public partial class SolutionPage
{
    [SitecoreField(FieldName = ISectionPageConstants.PageAssetFieldName)]
    public MediaFile PageAssetMedia { get; set; }

    [SitecoreQuery("./*/*", IsRelative = true)]
    public IEnumerable<ICategoryPage> Categories { get; set; }

    [SitecoreQuery("./*/*[@@templateid='{533670B4-BA56-4AD9-9840-7E34E1E0ED94}']", InferType = true, IsLazy = true,
        IsRelative = true)]
    public virtual IEnumerable<IApplicationPage> Applications { get; set; }

    [SitecoreQuery("./*/*[@@templateid='{F183AD73-9DE6-4035-99EE-446166D94A6D}']", InferType = true, IsLazy = true,
        IsRelative = true)]
    public virtual IEnumerable<IProductLinePage> ProductLines { get; set; }
}

Thanks Mike, I knew it was something small I was missing.

-K 
Reply all
Reply to author
Forward
0 new messages