User1724605321 posted
Hi tvb2727,
You could find the codes sample in
this thread .
For example , i have model like :
public class Records
{
public int id { get; set; }
public string name { get; set; }
public string parent_id { get; set; }
}
And the records in database:

Add the function :
private IEnumerable<Records> FindAllParents(List<Records> all_data, Records child)
{
var parent = all_data.FirstOrDefault(x => x.id.ToString() == child.parent_id);
if (parent == null)
return Enumerable.Empty<Records>();
return new[] { parent }.Concat(FindAllParents(all_data, parent));
}
Then get the current records and his parent records by :
var child = db.Records.First(x => x.id == id);
var parents = FindAllParents(db.Records.ToList(), child).ToList();
Please modify the code samples based on your requirement .
Best Regards,
Nan Yu