How does Entity Framework work with recursive hierarchies? Include() seems not to work with it

前端 未结 15 1804
再見小時候
再見小時候 2020-11-28 21:53

I have an Item. Item has a Category.

Category has ID, Name, Parent

15条回答
  •  生来不讨喜
    2020-11-28 22:34

    My suggestion would be

    var query = CreateQuery()
        .Where(entity => entity.Id == Id)
        .Include(entity => entity.Parent);
    var result = await FindAsync(query);
    
    return result.FirstOrDefault();
    

    and it means it will load single entity and all this entity.Parent entities recursive.

    entity is same as entity.Parent
    

提交回复
热议问题