【问题标题】:N2 CMS: Are nested collections of ContentItems possible?N2 CMS:内容项的嵌套集合是否可能?
【发布时间】:2011-01-11 11:58:28
【问题描述】:

N2中的一个页面可以添加任意数量的同一类ContentItems吗?它们可以嵌套吗?

即有没有办法将ContentItems 的集合定义为 N2 中的属性?如果可能的话,我还想嵌套这些,以便我们可以对数据运行更有意义的查询。 (即,不要使用难以查询的巨大 EditableTextRegions。)

我目前有以下模型作为“理想”,这可以 N2ified 吗? (为了清楚起见,我省略了属性和 N2 样式的 getter/setter)

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

public class Panel : ContentItem
{
    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
}

【问题讨论】:

    标签: c# collections nested n2 n2cms


    【解决方案1】:

    是的 - 在您的属性中使用 Get/SetDetailCollection 代替 Get/SetDetail。

    仅供参考,如果您使用的是 2.1,则可以将属性设置为 virtual 并省略 Get/SetDetail - 虽然不确定这是否适用于 DetailCollection 方法,但您可以将两者混合使用。

    不过,我会小心您的提议 - 像这样的嵌套集合可能会导致您 SELECT N+1 出现问题。如果你不能改变设计,那么我建议打开 N2 的数据库缓存(这只是 NH​​ibernate 的二级缓存),这样可以尽可能多地保存在内存中而不会过多地访问数据库。

    【讨论】:

    • 感谢您的回答,我现在通过循环遍历子集合并将成员转换为适当的类型,使其以不同的方式工作。此外,我们暂时停留在 2.0 版上 :( 我会尽快发布一些代码来说明...
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2010-09-05
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多