Why is this EF request taking too long?

We have an EF4 request that takes about 10 seconds. The query is not so complex, but since it includes many related tables, it takes a lot of time. I'm trying to speed it up.

The original query looks something like this (shortened for clarity) ...

var supportTickets = ctx.SupportTickets
  .Include(s => s.System.Customer.Country)
  .Include(s => s.System.Site.Address.Country)
  // other includes omitted
  .OrderByDescending(s => s.ID)
  .ToList();
var ticketsList = supportTickets
  .Select(CreateSupportTicketListOverview)
  .ToList();

CreateSupportTicketListOverview()is a method that takes an object and returns a DTO based on it. The shortened version looks like this ...

private static SupportTicketListOverview CreateSupportTicketListOverview(SupportTicket x)
  {
    return new SupportTicketListOverview {
      ID = x.ID,
      SystemNumber = x.System != null ? x.System.SystemNumber : "",
      CustomerName = x.System != null && x.System.Customer != null ? x.System.Customer.Name : "",
      ShortSummary = x.ShortSummary,
      SiteName = x.Site != null ? x.Site.SiteName : "",
      Status = x.Status != null ? x.Status.Description : "",
      // other properties omitted for clarity
    };
  }

, 10 4000 . SQL Server , 6,6. SQL, , 2 , . , ? , , ? , ?

, , . ( )...

  var tickets = ((SalesTrackerCRMEntities) getContext()).SupportTickets
      .AsNoTracking()
      .Include(s => s.System.Customer.Country)
      .Include(s => s.System.Site.Address.Country)
      .OrderByDescending(s => s.ID)
      .Select(t => new {
        SystemNumber = t.System != null ? t.System.DHRNumber : "", t.ID,
        CustomerName = t.System != null && t.System.Customer != null ? t.System.Customer.Name : "",
        SiteName = t.Site != null ? t.Site.SiteName : "",
        Status = t.Status != null ? t.Status.Description : "",
        // other stuff omitted
      })
      .AsEnumerable();
  var tickets1 =tickets
      .Select(t => new SupportTicketListOverview {
        ID = t.ID,
        SystemNumber = t.SystemNumber,
        CustomerName = t.CustomerName,
        ShortSummary = t.ShortSummary,
        SiteName = t.SiteName,
        Status = t.Status,
        // other stuff omitted
      })
      .ToList();

, 15 . , 0,7, .. , , EF 50% .

. , , , , . , EF. ( , , , ), ( ), ( , , ), ( ), ( ) ( ). . , , .

6.6 , EF 10 . .7s , 15 EF. .

- , ?

+4

Source: https://habr.com/ru/post/1660422/


All Articles