EF递归cte用于计算层次结构路径

时间:2018-02-19 08:36:39

标签: c# sql-server entity-framework ef-code-first calculated-columns

我有自引用表,我想为祖先路径添加计算列,例如:

public class PhysicalObject
{
    public PhysicalObject()
    {
        SubPhysicalObjects = new HashSet<PhysicalObject>();
    }

    [Key]
    [DatabaseGenerated(DatabaseGeneratedOption.Identity)]
    public int Id { get; set; }

    public int? ParentId { get; set; }

    [StringLength(150)]
    public string Title { get; set; }

    public string Path {get; set;}

    public virtual PhysicalObject Parent { get; set; }

    public virtual ICollection<PhysicalObject> SubPhysicalObjects { get; set; }
}

例如path =“1_50_60”

这里(1,50,60)是帮助我寻找树木的祖先。

我如何首先使用Entity框架代码实现这一目标?

0 个答案:

没有答案