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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 15, 20262026-05-15T06:44:15+00:00 2026-05-15T06:44:15+00:00

I am trying to create a pageing and sorting object data source that before

  • 0

I am trying to create a pageing and sorting object data source that before execution returns all results, then sorts on these results before filtering and then using the take and skip methods with the aim of retrieving just a subset of results from the database (saving on database traffic). this is based on the following article:

http://www.singingeels.com/Blogs/Nullable/2008/03/26/Dynamic_LINQ_OrderBy_using_String_Names.aspx

Now I have managed to get this working even creating lambda expressions to reflect the sort expression returned from the grid even finding out the data type to sort for DateTime and Decimal.

public static string GetReturnType<TInput>(string value)
        {
            var param = Expression.Parameter(typeof(TInput), "o");
            Expression a = Expression.Property(param, "DisplayPriceType");
            Expression b = Expression.Property(a, "Name"); 
            Expression converted = Expression.Convert(Expression.Property(param, value), typeof(object));
            Expression<Func<TInput, object>> mySortExpression = Expression.Lambda<Func<TInput, object>>(converted, param);
            UnaryExpression member = (UnaryExpression)mySortExpression.Body;
            return member.Operand.Type.FullName;
        }

Now the problem I have is that many of the Queries return joined tables and I would like to sort on fields from the other tables.

So when executing a query you can create a function that will assign the properties from other tables to properties created in the partial class.

public static Account InitAccount(Account account)
        {
            account.CurrencyName = account.Currency.Name;
            account.PriceTypeName = account.DisplayPriceType.Name;
            return account;
        }

So my question is, is there a way to assign the value from the joined table to the property of the current table partial class? i have tried using.

from a in dc.Accounts
                                 where a.CompanyID == companyID
                                 && a.Archived == null
                                 select new { 
PriceTypeName = a.DisplayPriceType.Name})

but this seems to mess up my SortExpression.

Any help on this would be much appreciated, I do understand that this is complex stuff.

  • 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-15T06:44:16+00:00Added an answer on May 15, 2026 at 6:44 am

    This is a functional programming thing. Mutating Account by doing an assignment is out. New-ing up a new instance of the shape you want is in.

    Step 1: declare a class that has the shape of the result you want:

    public class QueryResult
    {
      public int CompanyID {get;set;}
      public string CurrencyName {get;set;}
      public string PriceTypeName {get;set;}
    }
    

    Step 2: project into that class in your query

    from ...
    where ...
    select new QueryResult()
    {
      CompanyID = a.CompanyID,
      CurrencyName = a.Currency.Name,
      PriceTypeName = a.PriceType.Name
    };
    

    Step 3: Profit! (order by that)

    The query generator will use the details of your QueryResult type to generate a select clause with that shape.

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

Sidebar

Related Questions

I'm currently trying create a service that will return results of a OLAP cube
I am trying create a WCF Data Services ServiceOperation that does grouping on the
I am trying to create an app with horizontal scrolling, so that one would
I'm trying create a box in my Django app that displays text (and possibly
I'm trying to write a linq to sql method that handles sorting, paging, and
I'm trying create a gui using Tkinter that grabs a username and password and
I'm trying create an immutable object and initialise it from xml config file in
I am trying create a WCF service that leverages the WPF MediaPlayer on the
I am trying create a data.frame from which to create a graph. I have
I am trying create a layout. There are several inner layouts that should like

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.