Skip to content

EF CORE 5.0 ThenInclude OrderBy, uses PK before OrderBy field, rendering it useless #26343

@waywardcode

Description

@waywardcode

Has there been any progress with this? Ordering navigation properties still does not translate into the expected ordering in EFC5.0.5

var form = _db.Forms
  .Include(x => x.Sections)
  .ThenInclude(x => x.Rows.OrderBy(y => y.Order)) //Nope!
  .ThenInclude(x => x.Fields.OrderBy(y => y.Order)) //Nope here too!
  .ThenInclude(x => x.FieldType)
  .AsSplitQuery()
  .SingleOrDefaultAsync(x =>
      x.Id == formId)

If there is no intention of ever fixing this, it might be best to show a warning when an attempt to order a navigation property is made to avoid confusion.

Originally posted by @Bitz in #9067 (comment)

Example output on ORDERBY inside ThenInclude from EF

ORDER BY [a].[AreaId], [a].[NavBlockSortOrder], [a].[NavBlockId], [n].[AreaId], [n0].[NavBlockId], [t0].[NavGroupId], [t0].[NavBlockId], [t0].[SortOrder]

  • notice the last three, switching [t0].[NavGropuId] with [t0].[SortOrder] works as expected, but not as shown above

Any solution to this, hidden unknown dark magic or otherwise? :)

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions