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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:08:43+00:00 2026-05-23T12:08:43+00:00

I would Like to sort the keywords by its sort property. I have a

  • 0

I would Like to sort the keywords by its sort property.
I have a one-many relationship between page -> keyword.

Question: If I perform a comprehension query as:

IEnumerable<page> query = from p in contxt.pages where p.ID == myId select p;

IEnumerable<page> pge = query.First();

Could I expect a single page record set with all the page’s properties and one keyword collection?

My understanding is since there exist a one-many relationship, I don’t have to perform a join. The Linq to Entity framework should have knowledge of this relationship, and return a collection.

So this is my understanding, so when I try to sort on keyword.sort, the keyword is out of scope:

    IEnumerable<page> query = from p in contxt.pages where p.ID == myId
orderby p.keywords. select p;

Utilizing the above understanding I thought the query is incorrect because keywords is returned as a collection, so I must perform a sort as follows:

    PageKeywords pageKeywords = new PageKeywords();
    Keywords keywords;

    IEnumerable<page> query = from p in contxt.pages 
where p.ID == vals.pageId select p;

    page pge = query.First();

    pageKeywords.keywords = new List<Keywords>();

    pageKeywords.id = pge.ID;
    pageKeywords.description = pge.descp;
    pageKeywords.title = pge.title;
    pageKeywords.showTitle = pge.showTitle;
    pageKeywords.keywords = pge.keywords.OrderBy(k => k.sort);

    foreach (var item in pageKeywords.keywords)
    {
    keywords = new Keywords();
    keywords.id = item.id;
    keywords.name = item.name;
    keywords.sort = item.sort;
    pageKeywords.keywords.Add(keywords);
    }

However this did not work. The keywords were not sorted by sort? The code above does work, however I need the keywords to be sorted by sort property. The keywords collection isn’t being sorted.

I also tried:

pageKeywords.keywords.Sort((x, y) => int.Compare(x.sort, y.sort));

Which did not work.

I have tried to understand, but I am missing something? Any suggestions would be appreciable.

enter image description here

  • 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-23T12:08:43+00:00Added an answer on May 23, 2026 at 12:08 pm

    Try this:

    var query = from p in contxt.Pages 
                where p.ID == vals.PageId 
                select new PageKeywords 
                    {
                        Id = pge.Id,
                        Description = pge.Descp,
                        Title = pge.Title,
                        ShowTitle = pge.ShowTitle,
                        Keywords = pge.Keywords.OrderBy(k => k.sort)
                    };
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have an array that I would like to sort using a date field
I have a result from an SQL query that I would like to sort
I would like to sort a vector vector<myClass> object; Where myclass contains many int
I would like to sort JTable rows based on one hidden column. Say I
I have a list that I would like to sort in multiple ways. My
I have an array and would like to sort all but the last n
I would like to sort an array in ascending order using C/C++ . The
I would like to sort a matrix according to a particular column. There is
I would like to sort an array of strings in a directory, given a
I would like to sort the data of a core data NSSet (I know

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.