Hierarchy Problem -> Replace Recursion with Linq Join?

后端 未结 4 1322
离开以前
离开以前 2020-12-16 07:45

I have a self referential table, which has ID, ParentID (nullable).

So, the table contains many nodes, each node could be the root in the hierarchy (parent is null),

4条回答
  •  慢半拍i
    慢半拍i (楼主)
    2020-12-16 08:21

    Basically I'm going with something like this as discussed in the SO link you proivded.

    public IQueryable GetCategories(Category parent)
    {
        var cats = (parent.Categories);
        foreach (Category c in cats )
        {
            cats  = cats .Concat(GetCategories(c));
        }
        return a;
    }
    

    CTEs are probably the best solution but I'd like to keep things all in the same tier for now.

提交回复
热议问题