4
votes

I am trying to get all items at the current item level. I am using Glass Mapper SitecoreQuery for the same. I am able to get the current item but not able to map all siblings

public class TestModel:BaseModel
{
    [SitecoreQuery("../*")]
    public virtual IEnumerable<Model1> Siblings { get; set; }
}

[SitecoreType(AutoMap = true)]
public class Model1 : BaseModel
{

}

Base Model has all the required fields and correctly mapped. I am actually trying to display all items at the level of current item.

1
Try to add second parameter to SitecoreQuery : IsRelative = true like that: [SitecoreQuery("../*", IsRelative = true)]Marek Musielak
Are you trying to get all items at the same level or siblings only (i.e. excluding the current item)?jammykam
IsRelative at the end is important, it tells Glass.Mapper to execute the query relative to the item the class represents. Also you should add [SitecoreType(AutoMap = true)] above your TestModel class.Santiago Morla
Thanks . "IsRelative = true" worked for me .Deb
@Deb I'm glad it helped. Comment converted into an answer.Marek Musielak

1 Answers

0
votes

Add second parameter to SitecoreQuery : IsRelative = true like that:

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

It tells Sitecore to start query at your item level instead of starting at the tree root.

You can find more information in the Official Sitecore Glass Mapper Tutorial