Search code examples
c#entity-frameworklinq.net-coreodata

OData $top query in LINQ expression could not be transalted and will be evaluated locally using EF Core and .NET Core 2.2


I have an OData endpoint in my .NET Core API:

[EnableQuery]
[ODataRoute]
[HttpGet]
public IQueryable<MerchantDto> GetAll()
{
    return _context
        .Merchants
        .Where(x => !x.IsDeleted)
        .ProjectTo<MerchantDto>(_mapper.ConfigurationProvider);
}

It generates an SQL without LIMIT statement (postgres db) and this warning appears:

The LINQ expression 'Take(__TypedProperty_1)' could not be translated and will be evaluated locally.

How can I make this query to DB to include the OData $top? It is always getting the whole table records first.


Solution

  • I had a wrong object mapping configuration that caused that problem.