【问题标题】:SubSonic and Tree table structureSubSonic 和树表结构
【发布时间】:2009-10-23 02:20:16
【问题描述】:

我必须在我的数据库中存储一个树状结构(例如文件夹)。我选择的模型非常简单:表有一个 FolderId(PK、int、identity)、一些随机属性和一个可为空的 ParentId(与 FolderId、int、可空的相同表 FK)。

一切都很好。我正在使用 SubSonic 的 ActiveRecord 模板。有什么方法可以让我生成的文件夹类具有父/子属性,而不是简单的“文件夹”?

我怀疑我必须编辑模板,可能是 ActiveRecord.tt。如果是这样,有人可以指出我的起点吗?也许有人做过类似的事情?

【问题讨论】:

    标签: subsonic tree


    【解决方案1】:

    我想现在已经太迟了:我可以简单地做一些事情

    partial class Folder
    {
        public Folder Parent
        {
            get {
                if (_ParentId.HasValue)
                {
                    var repo = ACME.Folder.GetRepo();
                    return
                        (from items in repo.GetAll()
                         where _ParentId.Value == items._FolderId
                         select items).First();
                }
                else 
                    return null;
            }
        }
    
        public IQueryable<Folder> Children
        {
            get {
                var repo = ACME.Folder.GetRepo();
                return from items in repo.GetAll()
                       where _FolderId == items.ParentId
                       select items;
            }
        }
    }
    

    【讨论】:

      【解决方案2】:

      所有生成的类都是Partials,所以你可以做你上面做的事情,但只需为它创建一个partial类,这样它就都在“同一个”类中......

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-10-22
        • 2011-01-31
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多