从自我引用表获取层次结构需要花费大量时间才能生成Linq

时间:2018-08-23 11:34:23

标签: c# linq get hierarchy

我想从实体框架linq中的自引用表中获取层次结构,但是通过Linq,要花很多时间来获取层次结构。在本地主机上,时间大约为5至10分钟。

表是

Group table 我想在层次结构中映射以上表格

public class GroupHierarchy
    {
        public string Name { get; set; }
        public int Id { get; set; }
        public int? ParentGroupId { get; set; }
        IList<GroupHierarchy> Children { get; set; }
        public int HierarchyDepth { get; set; }
    }

Linq查询

var hierachy = _unitOfWork.GroupRepository.GetAllGroups().Where(g => g.GroupParentId == null);
var groups = Mapper.Map<List<GroupHierarchy>>(hierachy);

此查询是否需要花费大量时间(5-10分钟)来获取2000条记录才能得到结果,有人可以帮我吗

谢谢 马赫什

0 个答案:

没有答案
相关问题