我有自引用表,我想为祖先路径添加计算列,例如:
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框架代码实现这一目标?