views:

281

answers:

2
IQueryable<WebEvent> mySearch = 
    eventDC.GetBooks()
        .Where(p => p.Price.Any(d => d.EventDatetime.Month == fromDate.Month 
                                     && d.EventDatetime.Year == fromDate.Year))
        .WithGroup(groupId)
        .OrderBy(p => p.Price.Where(r => r.Datetime >= fromDate)
                             .OrderBy(q => q.Datetime)
                             .FirstOrDefault().Datetime);
List<Book>ventsList = mySearch.ToList<Book>();

We have such a long query, and it consume much time to get the books and sorting, after performance test , we found response time for the page which contains this query exceed 10 seconds, and we need to seek to solve this and reduce the response time.

Do anyone have any suggestions ?

+1  A: 

What exactly are you trying to do? Can you give me an idea of the schema here?

This seems like an odd statement to me since I don't know the schema:

p => p.Price.Any(d => d.EventDatetime.Month...

However, I'm gonna take a shot in the dark here and say that you might have an issue with:

eventDC.GetBooks()

if that method calls a Stored Procedure or otherwise does a "Select * From Books" on the database, then what you're actually doing is:

  1. Selecting ALL books from the DB
  2. Taking the resulting list and selecting only the books you want from it

If this is the case, then that's probably your biggest problem.

statichippo
Exactly what I was going to say. @MemoryLeak To test it, split the lines of code and step through it to see which seems to take the longest amount of time. The `p.Price.Any(` choice is confusing me also.
Codesleuth
A: 

Hello,

Typically examine the SQL to see what it's producing, which you can do inline. There is a tool that can help you do that, it's called LinqPad, and you can create a LINQ query and play around with tweaking the LINQ query. Also, looking for places to add indexes; this can speed up performance too (too many indexes can hurt performance so be careful too).

Brian