c# - N2 内容管理系统 : Are nested collections of ContentItems possible?

标签 c# collections nested n2 n2cms

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

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

我目前有以下模型作为“理想”模型,它可以被 N2 化吗? (为清楚起见,我省略了属性和 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
}

最佳答案

是的 - 在您的属性中使用 Get/SetDetailCollection 而不是 Get/SetDetail。

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

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

关于c# - N2 内容管理系统 : Are nested collections of ContentItems possible?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4657357/

相关文章:

c# - 在 64 位整数中查找最高和最低有效位集的快速方法

c# - 如何将查询字符串映射到列表字典

java - 归还藏品

c# - 在不超过最后一页的情况下从集合中获取一页?

lua - Lua 中的嵌套表和数字键

c# - 为什么我需要接口(interface)?

c# - 使用日期时间列设置 LinqDataSource Where 子句

C#:如何使用 LINQ 从 IDictionary<E, ICollection<T>> 的集合中删除项目?

html - 同一类标签上的 CSS 嵌套规则

css - 当文本嵌套在大约 5 个生成的 DIV 标签中时,将文本获取到 "display:inline"的简单方法?