Question

In ASP.NET MVC 4, I have a [HttpGet] action method, that returns a JsonResponse.

    public JsonResult List(int domainId)
    {
            ....
    }

When I call this method with the browser, by typing the URL: localhost:43229/GroupsAjax/List?domainId=1, I have to wait like 50 seconds to see the results.

My first thought was that the method was too slow, but by adding breakpoints I noticed that it already had returned.

Breakpoints

I tried with Iexplorer too and the same lag happend. In chrome, the lag was associated with the "Waiting time", according to the timeline

What might be happening?

Était-ce utile?

La solution

I'm reviewing old questions (by me) without answers, the answer to this is/was:

I should have included the AsJson() code:

    public dynamic AsJson()
    {
        return new
        {
           name = this.Name,
           membersCount = this.Members.Count()
        }
    }

The query was this:

 dynamic results = from g in groups.ToList()
                   select g.AsJson();

The "this.Members.Count()" is run in memory because of the ToList().

So: the query is divided in to parts: SQL To Entities and SQL To Objects

The first part was fast, the second was slow (has to do Members.Count() N times, being N the number of results in "groups.ToList()"

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top