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 6976685
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T17:31:44+00:00 2026-05-27T17:31:44+00:00

I have a Action model with Session Navigation Property, Consider this code: var x=db.Actions.OrderBy(p

  • 0

I have a Action model with Session Navigation Property,

Consider this code:

var x=db.Actions.OrderBy(p => p.Session.Number).ThenBy(p => p.Date);//it's OK

x is a ordered Action, but when grouped on x, group not iterate on x(base on Action.Session) manually on ordered enumerable:

var y=x.GroupBy(p=>p.Session).ToArray()

y have a group(Key,IGrouping) of sessions but why group.Key not ordered base on Session.Number?

How to i reached a group of Session order by number and each group ordered by date?

  • 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-27T17:31:45+00:00Added an answer on May 27, 2026 at 5:31 pm

    Because it’s Enumerable.GroupBy that preserves order. No such promise is made for Queryable.GroupBy.
    From the documentation of the former:

    The IGrouping(Of TKey, TElement) objects are yielded in an order based on
    order of the elements in source that produced the first key of each
    IGrouping(Of TKey, TElement). Elements in a grouping are yielded in the order
    they appear in source.

    You’re calling the latter, and the above is not mentioned. Call OrderBy after GroupBy to make it work.

    Update: since you apparently want to sort on more than just the GroupBy key, you should be able to use another GroupBy overload to specify that each session’s list of actions is to be sorted:

    db.Actions.GroupBy(
        p => p.Session,
        (session, actions) => new {
            Session = session,
            Actions = actions.OrderBy(p => p.Date)
        }).OrderBy(p => p.Session.Number).ToArray();
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have a model, smth like this: class Action(models.Model): def can_be_applied(self, user): #whatever return
Consider the following code: [Authenticate(Order = 1)] public ActionResult SomeActionThatRequiresAuthentication() { var model =
I have an action like this: public class News : System.Web.Mvc.Controller { public ActionResult
i have form action file in another directory but some file send to this
I have this Pin Model: class Pin < ActiveRecord::Base belongs_to :user belongs_to :image accepts_nested_attributes_for
I have this in my controller public ActionResult Testing() { CustomerContactModel model = new
I currently have this: Hotels Controller class HotelsController extends AppController { var $name =
I have a User controller and User model. This model and associated database table
I have some repetitive code that is used by a few of my actions
I have following Model t.string name t.date start_at t.date end_at t.datetime created_at t.datetime updated_at

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.