We are using the ASP.NET Zero template version 9.0.1. How do you go about sorting child entites when they are retrieved using the GetAllIncluding method? According to the Microsoft documentation we should be able to do the following. https://docs.microsoft.com/en-us/ef/core/querying/related-data#filtered-include.
return await _entityRepository.GetAllIncluding( e => e.childEntities .OrderBy( ce => ce.childProperty) ) .ToListAsync();
2 Answer(s)
-
0
hi
You can order the children entities after query.
https://entityframeworkcore.com/knowledge-base/54859088/orderby-in-include-child-using-ef-core
-
0
That worked for us. Our method now looks similar to the following. Thank you.
public async Task<List<ParentItem>> GetParentItems() var parentItems = _parentItemRepository.GetAllIncluding( p => p.ChildItem1, p => p.ChildItem2 ) .AsNoTracking() .ToListAsync(); parentItems.Result.ForEach( p => { p.ChildItem1 = p.ChildItem1.OrderBy(c => c.ChildProperty).ToList(); p.ChildItem2 = p.ChildItem2.OrderBy(c => c.ChildProperty).ToList(); }); return await parentItems; }