0

我有一个启用 oData 的 web api 功能

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

服务层调用基于 Mongodb 的 Repository 模式的实现。

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

其中 GetAll 在 Repository 层中实现,例如

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

其中 _collection 是 c# 驱动程序的 MongoCollection。

当我打电话时

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

我得到前 10 条记录,但它从数据库中提取所有记录并将我送回前 10 条。请指导我们如何从数据库中仅提取所需的集合。

4

1 回答 1

0

评论转为回答:

您没有从 GetAllStoreCommands() 返回 IQueryable。您的返回类型必须是 IQueryable()。要从驱动程序中获取它,它应该是 _collection.AsQueryable()。

于 2015-05-21T17:07:52.717 回答