I have a query:
public async Task<IEnumerable<CategoryDto>> GetCategoriesAsync()
{
var dto = await _context.Categories.FromSqlRaw(
@"SELECT * FROM [cp].[GetCategoryTree]")
.ProjectTo<CategoryDto>(_mapper.ConfigurationProvider)
.AsNoTrackingWithIdentityResolution()
.ToListAsync();
return dto;
}
It produces this sql:
SELECT [c].[banner_group_id], [c].[category_id], [c].[description], [c].[inactive], [c].[issitecategory], [c].[keywords], [c].[category_name], [c].[page_content], [c].[parent_category_id], [c].[sort_order], [c].[title], [b].[banner_group_id], [b].[category_id], [b].[description], [b].[inactive], [b].[issitecategory], [b].[keywords], [b].[category_name], [b].[page_content], [b].[parent_category_id], [b].[sort_order], [b].[title]
FROM (
SELECT * FROM [cp].[GetCategoryTree]
) AS [c]
LEFT JOIN [bma_ec_categories] AS [b] ON [c].[category_id] = [b].[parent_category_id]
ORDER BY [c].[category_id], [b].[category_id]
The output from [cp].[GetCategoryTree]
is already sorted in that view. Why is EF Core adding an extra ORDER BY
on the end? Can I tell EF Core to not sort?