我有一个启用 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 条。请指导我们如何从数据库中仅提取所需的集合。