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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 9, 20262026-06-09T14:26:38+00:00 2026-06-09T14:26:38+00:00

Given a Parent and a valid columnName, I want to find all the related

  • 0

Given a Parent and a valid columnName, I want to find all the related Children, ordered by a dynamic column name. Here’s how I thought my code would look:

Parent.                                             // EntityObject
Children.                                           // EntityCollection
Where(c => c.Gender == 'm').                        // IEnumerable
OrderBy(columnName, ListSortDirection.Ascending).   // -- not available --
Skip(pages * pageSize).Take(pageSize);

IEnumerable.OrderBy(string columnName) doesn’t exist. Looking around to accomplish the “sort by dynamic column name”, I started with this excellent-looking solution: How do I create an expression tree for run time sorting? , but this operates on an IQueryable

If it did, I assume it would bring the records over the wire to sort and diminish the performance of my pager anyway. So I reordered:

Repository.                                         // Repository
Children.                                           // ObjectSet
Where(c => c.Parent == Parent && c.Gender == 'm').  // ObjectQuery, runtime error
OrderBy(columnName, ListSortDirection.Ascending).   // IOrderedQueryable
Skip(pages * pageSize).Take(pageSize);

ObjectSet and ObjectQuery implement OrderBy(string columnName), and this code compiles, but yields the error:

Unable to create a constant value of type ‘DataModel.Parent’. Only
primitive types (‘such as Int32, String, and Guid’) are supported in
this context.

Of course, I can get the parent ID, but the Child.ParentReference is also a non-primitive type.

I can think of a few ways that would result in loading the entire recordset across the wire, but I feel like I must be missing something, because it must not be so hard to get a set of basic directive through to the database using all MS-centric technologies.

edit: pretend I’m http://en.wikipedia.org/wiki/Quiverfull , and need to paginate my children. 🙂
edit2: clarified my need to query a dynamic column name.

  • 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-09T14:26:40+00:00Added an answer on June 9, 2026 at 2:26 pm

    So there were a couple issues I was having, both mentioned in the question title.

    Sorting by a run-time-selected, or dynamic, column name required some expression building. I used @Slace’s popular extension method here.

    That required an IQueryable. IQueryable works for me, because every time I was accidentally transforming my query into an enumerable, I was of course bringing all the results back over the wire before paging, which I was trying to avoid. But I still needed a way to get an IQueryable for results with a relationship to an entity I already held.

    It was something simple I overlooked, just joining on the Entity.Id worked, and didn’t result in redundant joins at the datasource. Not quite as object-oriented as I expected from EF, but it will do.

    Repository.                                         // Repository
    Children.                                           // ObjectSet
    Where(c => c.Parent.Id == Parent.Id).               // ObjectQuery, works fine
    OrderBy(columnName, ListSortDirection.Ascending).   // IOrderedQueryable
    Skip(pages * pageSize).Take(pageSize);              // Only transfers 1 page
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Given a parent URL (say http://dir.yahoo.com/News_and_Media/ ), I want to scrape all URLs which
Given a simple parent/child class structure. I want to use linqkit to apply a
Given the following classes: @XmlRootElement(name = parent) class Parent { private Child child; //
Given the relationship expressed below: class Parent < ActiveRecord::Base has_many :children, :dependent => :destroy
I have a plugin that finds all img elements within a given parent element.
Given a Category (parent) and Product (child) tables in a database, say, I want
I am trying to figure out children processes of a given parent from ps
how can i get immediate parent of a given element ? $(e.target).parent() ?
Given the following simple program: import wx class TestDraw(wx.Panel): def __init__(self,parent=None,id=-1): wx.Panel.__init__(self,parent,id,style=wx.TAB_TRAVERSAL) self.SetBackgroundColour(#FFFFFF) self.Bind(wx.EVT_PAINT,self.onPaint)
I have an odd linq subquery issue. Given the following data structure: Parents Children

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.