Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7715155
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 1, 20262026-06-01T02:18:51+00:00 2026-06-01T02:18:51+00:00

I have two tables a parent and a child table. The child table has

  • 0

I have two tables a parent and a child table. The child table has a column sortorder (a numeric value). Because of the missing support of the EF to persist a IList inclusive the sort order without exposing the sortorder (see: Entity Framework persisting child collection sort order) my child class has also a property SortOrder, so that i can store the children with the sort order.

In contrast to the author of the referenced question I try to load the children always sorted. So if I load a parent instance I expect, that the child collection is sorted by sort order. How can I achieve this behaviour with the Code First Fluent API and POCO’s?

Hint: It’s not an option to call .Sort(…) on the child collection.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-01T02:18:51+00:00Added an answer on June 1, 2026 at 2:18 am

    You cannot achieve it directly because neither eager or lazy loading in EF supports ordering or filtering.

    Your options are:

    • Sort data in your application after you load them from database
    • Execute separate query to load child records. Once you use separate query you can use OrderBy

    The second option can be used with explicit loading:

    var parent = context.Parents.First(...);
    var entry = context.Entry(parent);
    entry.Collection(e => e.Children)
         .Query()
         .OrderBy(c => c.SortOrder)
         .Load();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have two tables, Parent and Child. The column Parent.favorite_child has a foreign key
I have a table with two child tables. For each record in the parent
I have two tables with parent - child relationship: PARENT table with id as
I have two tables, one parent and one child table. Child will have many
I have two tables with a join table between them: Parent: Pages Child: Things
Ok, I have three tables. The parent table is Listings and two child tables
Lets say I have two tables - child and parent with many-to-one relation. What
I have Two tables like this: Table categories: columns: id, name, parent 1, Foods,
I have two linqTOsql entities that has a parent and child relationship, one to
I have to search in two tables that are in a parent-child relation (1:n)

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.