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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 20, 20262026-05-20T12:39:20+00:00 2026-05-20T12:39:20+00:00

I am building an ASP.Net MVC 3 application with Entity Framework 4. When the

  • 0

I am building an ASP.Net MVC 3 application with Entity Framework 4. When the two pieces of code below are executed, both variables (query1 and query2) have a return type of

System.Data.Objects.ObjectQuery<Asset.Model.Equipment>

Query1 uses a direct instance of the ObjectContext, however, Query2 uses a repository pattern, ie, it calls GetEquipment in EquipmentService, which in turns calls the same named method in Equipment Repository. Both the methods in the Service and Repository return

IQueryable<Equipment>

How, here’s my question, how come query2 will only work when I include

using System.Linq.Dynamic;

At the top of my controller

using (AssetEntities context = new AssetEntities())
        {
            var query1 = context.Equipments
            .OrderBy("it." + sidx + " " + sord)
            .Skip(pageIndex * pageSize)
            .Take(pageSize);
        }


        var query2 = equipService.GetEquipment()
            .OrderBy(sidx + " " + sord)
            .Skip(pageIndex * pageSize)
            .Take(pageSize);

If I omitt System.Linq.Dynamic from my controller, I get an error within Query2 at

.OrderBy(sidx + " " + sord)

Which states

The type arguments for method 'System.Linq.Queryable.OrderBy<TSource,TKey>(System.Linq.IQueryable<TSource>, System.Linq.Expressions.Expression<System.Func<TSource,TKey>>)' cannot be inferred from the usage. Try specifying the type arguments explicitly

Does anyone know why query1 can work without having to use System.Linq.Dynamic, but that query2 needs it to execute?

Thanks Everyone.

  • 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-20T12:39:21+00:00Added an answer on May 20, 2026 at 12:39 pm

    In the first query context.Equipments has type ObjectQuery<Equipment>. The ObjectQuery<T> has the method OrderBy(string) which one need for .OrderBy("it." + sidx + " " + sord). So the first query work.

    In the second query you use equipService.GetEquipment() of the type IQueryable<Equipment>. The IQueryable<T> has only extension method OrderBy with Expression<Func<T, TKey>> as the parameter instead of string. So to use OrderBy with IQueryable<Equipment> you have to write something like

    equipService.GetEquipment().OrderBy(e => e.equipmentID)
    

    but it is not what you can use. To you need another extension method, which can provide you the LINQ Dynamic Query Library in form System.Linq.Dynamic.

    In many cases LINQ to Entities has many restrictions, but in your case it has more advantages as LINQ to SQL. So I recommend you to stay by LINQ to Entities in your case. I am sure that in the way you will receive better performance because of native support of all function directly in the Entity Framework which you use.

    Because LINQ to Entities or ObjectQuery<Equipment> supports Where(string) method (to be exactly ObjectQuery.Where(string predicate, params ObjectParameter[] parameters) method) you can relatively easy implement filtering/searching in jqGrid. The usage of .Where can be

    .Where("it.equipmentID < 100")
    

    or

    .Where("it.equipmentID < @maxId", new ObjectParameter ("maxId", 100))
    

    for example (the usage of “maxId” instead of “@maxId” in the ObjectParameter is not typing error).

    UPDATED: In “UPDATED” part of the answer you can find the example which shows how to implement filtering/searching in jqGrid based on the idea which I described above.

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

Sidebar

Related Questions

I am building an ASP.Net MVC 3 Web application with Entity Framework 4.1. I
I am building an ASP.NET MVC web application using entity framework DbContext using the
I am building an ASP.Net MVC 3 web application using Entity Framework 4.1 with
I am building an ASP.Net MVC 3 Web application using Entity Framework 4.1. To
I am building a web application using ASP.NET MVC that has two very distinct
I'm building an Asp.net MVC 2 application. I have an entity called Team that
I'm building an ASP.Net MVC 2 application with a component architecture. There are two
I am currently building a very small/simple web application in ASP.NET MVC with ADO.NET
I'm in the process of building my first web application using ASP.NET MVC 2
We are building an ASP.Net MVC 2 multi-tenant application on SQL Server using the

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.