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

  • Home
  • SEARCH
  • 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 4036768
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:15:51+00:00 2026-05-20T12:15:51+00:00

In SQL I can write SELECT a.*, b.* FROM master_table a LEFT JOIN detail_table

  • 0

In SQL I can write

SELECT a.*, b.*
FROM master_table a
LEFT JOIN detail_table b ON (b.a_id = a.id)
ORDER BY a.id, b.order_field

Is it possible to do the same with EF4 ?
I cannot understand how to specify order by clause.
So far I tried

List<master_table> l = context.master_table.Include("detail_table").
OrderBy(x=>x.id).
ThenBy( //here is the problem, y=>y.detail_table.order_filed doesn't compile, 
//y=>y.detail_tables.OrderBy(z=>z.order_field) - throws a run-time exception
).
ToList();

Thanks.

  • 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-05-20T12:15:52+00:00Added an answer on May 20, 2026 at 12:15 pm

    The syntax in LINQ to Entities can be similar to your SQL query:

    var result = from a in context.master_table
                 join b in context.detail_table on a.id equals b.a_id
                 orderby a.id, b.order_field
                 select new { /*...*/};
    

    Edit:

    With the clarification from your comment – The problem is that in the SQL query you have pairs of items that you are joining (a,b) – while in the Linq to Entities query you are trying to do you want a secondary order by a navigation property.

    The difference is that there’s a one to many relationship between the master_table entries and the detail_table entries in this context, you have a grouping by master_table entry already – given that it doesn’t make sense (to the compiler or in general) to be able to express that sort order on the detail_table level.

    I would just enforce it when you enumerate the results – the master_table entries are already in the right order, just return the details using foo.detail_tables.OrderBy(x=>x.order_field).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

In DB2, you can name a column ORDER and write SQL like SELECT ORDER
Can anyone tell me how to write a nested SQL query like SELECT *
In SQL you can use SELECT * FROM INFORMATION_SCHEMA.TABLES etc to get information about
I want write this sql select statment in mysql v 3.23 select * from
In SQL one can write a query that searches for a name of a
I know that with mysql you can write SQL statements into a .sql file
Can anyone help me with the trying to write SQL (MS SqlServer) - I
I am trying to write a query for SQL Server 2005 but I can't
What SQL can be used to list the tables, and the rows within those
When I enter an object into the DB with Linq-to-SQL can I get the

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.