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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T19:07:11+00:00 2026-06-07T19:07:11+00:00

I’ve been learning C# / LINQ / ASP.NET / MVC 3 / EF for

  • 0

I’ve been learning C# / LINQ / ASP.NET / MVC 3 / EF for a few months now comming from Java / Icefaces / Ibatis base (Real world uses .NET D;). I really enjoy LINQ / Entity Framework from the .NET Framework but I’m having a few issues understand what’s really happening behind the scenes.

Here’s my problem:

I’m using a AJAX / JSON fed jQuery datatable (that I highly recommend to anyone in need of a free web datatable system by the way). I have a method in my MVC3 application that returns a JSON result of the data needed by the table, doing the sorting and all. Everything is working nicely and smoothly. However, I’m having a concern with the "dirty" hack I had to do to make this work.

Here’s the complete code:

//inEntities is the Entity Framework Database Context
//It includes the following entities:
//  Poincon
//  Horaire
//  HoraireDetail
//Poincon, Horaire and HoraireDetail are "decorated" using the Metadata technic which
//adds properties methods and such to the Entity (Like getEmploye which you will see in
//the following snippet)
//
//The Entity Employe is not a database data and therefor not handled by the EF.
//Instead, it is a simple object with properties that applies Lazy Loading to get an
//Employe Name based off of his Employe ID in the Active Directory. An employe object
//can be constructed with his Employe ID which will expose the possibility of getting
//the Employe Name from the AD if needed.

[HttpPost]
public JsonResult List(FormCollection form)
{
    String sEcho;
    int iDisplayStart;
    int iDisplayLength;
    String sSearch;
    int iSortingCols;
    Dictionary<String, String> sorting;

    try
    {
        sEcho = form["sEcho"];
        iDisplayStart = int.Parse(form["iDisplayStart"]);
        iDisplayLength = int.Parse(form["iDisplayLength"]);
        sSearch = form["sSearch"];
        iSortingCols = int.Parse(form["iSortingCols"]);

        sorting = new Dictionary<string,string>();
        for (int i = 0; i < iSortingCols; i++)
            sorting.Add(form["mDataProp_" + form["iSortCol_" + i]].ToUpper(), form["sSortDir_" + i].ToUpper());
    }
    catch
    {
        HttpContext.Response.StatusCode = 500;
        return null;
    }

    var qPoincon = inEntities.Poincons.AsEnumerable();
    var lPoincon = qPoincon.Select(o => new
    {
        o.id,
        emp = o.getEmploye(),
        o.poinconStart,
        o.poinconEnd,
        o.commentaire,
        o.codeExceptions
    }).AsEnumerable();

    //Search
    lPoincon = lPoincon.Where(p => (p.emp.empNoStr.Contains(sSearch) || p.emp.empNom.Contains(sSearch) || (p.commentaire != null && p.commentaire.Contains(sSearch))));

    //Keep count
    int iTotalDisplayRecords = lPoincon.Count();

    //Sorting
    foreach(KeyValuePair<String,String> col in sorting)
    {
        switch (col.Key)
        {
            case "EMPNO":
                if (col.Value == "ASC")
                    lPoincon = lPoincon.OrderBy(h => h.emp.empNo);
                else
                    lPoincon = lPoincon.OrderByDescending(h => h.emp.empNo);
                break;
            case "POINCONSTART":
                if (col.Value == "ASC")
                    lPoincon = lPoincon.OrderBy(h => h.poinconStart);
                else
                    lPoincon = lPoincon.OrderByDescending(h => h.poinconStart);
                break;
            case "POINCONEND":
                if (col.Value == "ASC")
                    lPoincon = lPoincon.OrderBy(h => h.poinconEnd);
                else
                    lPoincon = lPoincon.OrderByDescending(h => h.poinconEnd);
                break;
            case "COMMENTAIRE":
                if (col.Value == "ASC")
                    lPoincon = lPoincon.OrderBy(h => h.commentaire);
                else
                    lPoincon = lPoincon.OrderByDescending(h => h.commentaire);
                break;
        }
    }

    //Paging
    lPoincon = lPoincon.Skip(iDisplayStart).Take(iDisplayLength);

    //Building Response
    var jdt = new
    {
        iTotalDisplayRecords = iTotalDisplayRecords,
        iTotalRecords = inEntities.Poincons.Count(),
        sEcho = sEcho,
        aaData = lPoincon
    };
    return Json(jdt);
}

As you can see, when I’m grabbing the entire list of "Poincons" from the EF and turning it into a Enumerable. From my current understanding, turning the LINQ query into a Enumerable "kills" the link to the EF, or in other words, will generate the SQL required to get that list at that point instead of keeping the LINQ data until the end and execute a percise query that will return only the data you require. After turning this LINQ Query into a Enumerable, I’m heavily filtering the LINQ (since there is paging, sorting, searching in the datatable). This leads me to thinkg that what my code is currently doing is "Grab all the "Poincons" from the database and put it into the web server’s memory as a Enumerable, do your work with the Enumerable then serialize the result as a JSON string and send it to the client.

If I’m correct, the performance hit is quite heavy when you hit the couple thousand of entries (which will happen quite fast once in production… everytime an employe comes to work, it will add 1 entry. 100 employes, ~300 work days a year, you get the idea).

The reason for this hack is that the EF does not know what "getEmploye" method of "Poincon" is, therefor throwing an exception at runtime similar to this:

LINQ to Entities ne reconnaît pas la méthode « PortailNorclair.Models.Employe getEmploye() », et cette dernière ne peut pas être traduite en expression de magasin.

Approximated traduction (If anyone can let me know in a comment how to configure IIS / ASP.NET to display errors in english while keeping the globalization in a foreign language, I would be really grateful. French information about error messages is sometimes lacking):

LINQ to Entity does not recognize the method " PortailNorclair.Models.Employe getEmploye()" and the following could not be translated to a SQL expression.

The "getEmploye" method instances and returns a Employe object with the employe id found in the Poincon object. That Employe object has properties that "lazy loads" information like the employe name from the Active Directory.

So the question is: How can I avoid the performance hit from using .AsEnumerable() on the non-filtered list of objects?

Thanks a lot!

  • 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-07T19:07:12+00:00Added an answer on June 7, 2026 at 7:07 pm

    The “getEmploye” method instances and returns a Employe object with
    the employe id found in the Poincon object. That Employe object has
    properties that “lazy loads” information like the employe name from
    the Active Directory.

    You should be storing the Employee Name in the database, so you can then order, sort, skip and take in your Linq Query without having to load every employee object.

    If empNoStr, empNom, and empNo were all in the database, you could retrieve just the records you want, and call getEmploye() (loading whatever else you need from active directory, or wherever) for each of those.

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

Sidebar

Related Questions

I have a jquery bug and I've been looking for hours now, I can't
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
this is what i have right now Drawing an RSS feed into the php,
I'm parsing an RSS feed that has an &#8217; in it. SimpleXML turns this
I have a text area in my form which accepts all possible characters from
Does anyone know how can I replace this 2 symbol below from the string
I'm trying to decode HTML entries from here NYTimes.com and I cannot figure out
I have an MVC Razor view @{ ViewBag.Title = Index; var c = (char)146;

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.