Search code examples
mongodbasp.net-web-apiodatamongodb-.net-driverasp.net-web-api-odata

oData's skip() and top() pulling entire record set before filtering


i have an oData enabled web api function

[EnableQuery()]
    public IQueryable<StoreCommand> Get()
    {
        return _storeCommandService.GetAllStoreCommands().AsQueryable();
    }

the service layer calling Mongodb based Repository pattern's implementation.

public IEnumerable<StoreCommand> GetAllStoreCommands()
    {
        return _uow.StoreCommands.GetAll();
    }

where GetAll is implemented in Repository layer like

    public IList<TEntity> GetAll()
    {
        return _collection.FindAllAs<TEntity>().ToList();
    }

where _collection is a MongoCollection of c# driver.

when i make a call like

http://localhost:xxxx/api/storeCommandsrest?$skip=0&$top=10&$orderby=Name

i get top 10 records but it pulls all the records from the DB and send me back top 10. Please guide how we can pull only the required set from the DB.


Solution

  • Comment moved to answer:

    You aren't returning an IQueryable from GetAllStoreCommands(). Your return type must be an IQueryable(). To get that from the driver, it should be _collection.AsQueryable().