I have the following objects:

[![enter image description here](https://i.stack.imgur.com/M1nd3.png)](https://i.stack.imgur.com/M1nd3.png)

I want to be able to list all companies and order by the sum of the total order value.

I've tried this:

```cs
IQueryable<Company> query = _context.Companies
    .Include(c => c.InstalledBases)
        .ThenInclude(ib=>ib.Orders);

query = query.OrderBy(company => 
    company.InstalledBases.Sum(ib => 
        ib.Orders.Sum(order => order.Value)));

```

But this code gives me the warning: "The LINQ expression Sum() could not be translated and will be evaluated locally".
I have tens of thousands of companies, installed bases and orders so the query takes a long time to finish.

I'm using Asp Core 2.0.0

Is there any way to avoid the local evaluation to speed up the query?

**Edit:**

I also use Skip and Take to limit the companies currently viewed:

```
result = result.Skip(request.Start).Take(25);

```