Entity Framework Ordering Includes

前端 未结 7 1388
孤城傲影
孤城傲影 2020-11-27 21:11

I am trying to get something like the following to work:

_dbmsParentSections = FactoryTools.Factory.PdfSections
                        .Include(x => x.Ch         


        
7条回答
  •  不知归路
    2020-11-27 21:58

    I use this code por order the include, using a select and a function to order the collection. Is not the best but work fine if subcollection is small

       // GET: api/Tareas
        [HttpGet]
        public IEnumerable GetTareas()
        {
            var result = _context.Tareas
                .Include(p => p.SubTareas)
                .Select(p => SortInclude(p));
            return result;
        }
    
        private Tarea SortInclude(Tarea p)
        {
            p.SubTareas = (p.SubTareas as HashSet)?
                .OrderBy(s => s.Position)
                .ToHashSet();
            return p;
        }
    

提交回复
热议问题