开发者

N2 CMS: Are nested collections of ContentItems possible?

Can an arbitrary number of ContentItems of the same class to be added to a page in N2? And can they be nested?

I.e. Is there a way to define a collection of ContentItems as a property in N2? I’d also like to nest these if possible so we can run more meaningful queries against the data. (I.e. instead of using huge EditableTextRegions which will be difficult to query.)

I currently have the following model as an ‘ideal’, can this be N2ified? (I’ve left off attributes and N2 style getters/setters for clarity)

public class Link : ContentItem
{
    public string Text { get; set; }
    public string Title { get; set; }
    public string Url { get; set; }
}

public class Panel : Con开发者_开发知识库tentItem
{
    public string Title { get; set; }
    public string Text { get; set; }
    public List<Link> Links { get; set; } // Should show an expandable number of “Link” editors in the CMS editor
    public string ImageUrl { get; set; }
}

public class Page : ContentItem
{
    public string Title { get; set; }
    public string BodyText { get; set; }
    public List<Panel> Panels { get; set; } // Should show an expandable number of “Panel” editors in the CMS editor
}


Yes - instead of Get/SetDetail in your properties use Get/SetDetailCollection.

FYI if you're using 2.1 you can just make your properties virtual and leave off the Get/SetDetail - not sure if this works for the DetailCollection methods though, but you can mix the two.

I'd be careful with what you're proposing though - nesting collections like this is likely to cause you SELECT N+1 issues down the line. If you can't change the design then I'd recommend turning on N2's database caching (which is just NHibernate's 2nd level cache), this way as much as possible will be kept in memory without hitting the database too much.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜