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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T23:32:11+00:00 2026-05-17T23:32:11+00:00

Now this is a trick question because you cannot do this: var a =

  • 0

Now this is a trick question because you cannot do this:

var a = myDB.Where(p => p.field == "filter").OrderBy("it." + fieldname);

You could change the Where to accept a string, which allows you to change the OrderBy to accept a string, but that’s not the question.

How can you turn a string like “productID, productName” in to an OrderBy expression? If I am correct in thinking, maybe the question could be “how to turn a Specification Pattern in to an Expression delegate?”

The problem is I don’t know what table they want, and thus I don’t know the primary key. I used generics to represent the type of table.

public interface IRepository<E, C> where C : ObjectContext  // E is an Entity
{
  void Add(E entity);
  void Del(E entity);
  IList<E> Get(Expression<Func<E, bool>> filterLambda = null,   //Where clause
              Expression<Func<E, object>> orderbyLambda = null, //OrderBy
              int? page = null,                                 //Page to get
              int? pageSize = null,                             //Page Size
              Expression<Func<E, object>> selectLambda = null); //Populate Fields
  int Count(Expression<Func<E, bool>> filterLambda = null);
  bool SaveChanges();
}

The actual statement I use to pull content from the data context (data container?) is

this.GetEntity().Where(filterLambda)
                .OrderBy(orderbyLambda)
                .Skip(((int)page - 1) * (int)pageSize)
                .Take((int)pageSize)
                .Select(selectLambda).ToList();

I need the OrderBy() to implement .Skip() and .Take(). For all those of you who think you can do this are correct for Linq to SQL. However, Linq to Entities does not support it:

The method 'Skip' is only supported for sorted input in LINQ to Entities.
The method 'OrderBy' must be called before the method 'Skip'.
  • 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-17T23:32:11+00:00Added an answer on May 17, 2026 at 11:32 pm

    You don’t have to build the query in a single statement. As the query is not executed until you do the ToList at the end, you can use conditions to build it. Example:

    var query = myDB.Where(p => p.field == "filter");
    
    string sort = "productID, productName";
    
    string[] sortItems = sort.Split(new string[] {", "}, StringSplitOptions.None);
    switch (sortItems[0]) {
      case "productId": query = query.OrderBy(x => x.ProductId); break;
      case "productName": query = query.OrderBy(x => x.ProductName); break;
    }
    for (int i = 1; i < sortItems.Length; i++) {
      switch (sortItems[i]) {
        case "productId": query = query.ThenBy(x => x.ProductId); break;
        case "productName": query = query.ThenBy(x => x.ProductName); break;
      }
    }
    query = query.Skip(10).Take(10);
    

    (However, the type of the query object may change when you add sorting (e.g. from IEnumerable<T> to IOrderedEnumerable<T>), so you might need some more variables to store the different stages.)

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

Sidebar

Related Questions

(EDIT: This question is now outdated for my particular issue, as Google Code supports
Now I have seen this question in another forum but it didn't had an
I read that this is a tricky question because an applet is run in
This is a multiple part question, mostly because my ignorance on the matter has
I've been trying to track this one for literally a month now without any
Given this: Public Sub timReminder_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) If DateTime.Now()
Now this is .NET but I am sure the principal should apply to all
Now this must be easy, but how can sum two NSNumber ? Is like:
The best I can come up with for now is this monstrosity: >>> datetime.utcnow()
Does your work environment use Harvest SCM? I've used this now at two different

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.