2012-06-12 29 views
2

我陷入了一些奇怪的问题。下面是代码 AccountsController.cs

// GET /api/accounts 
[HttpGet] 
[Queryable(ResultLimit = 50)] 
public IQueryable<AccountDto> Get() 
{ 
    return this.service.Get(); 
} 

服务在这里 - 这是AccountService.cs

public IQueryable<AccountDto> Get() 
{ 
    return this.readModel.Get(); 
} 

和readModel的类型是AccountsReadModel的

public IQueryable<AccountDto> Get() 
{ 
    return Database.GetCollection<AccountDto>("Accounts").AsQueryable(); 
} 

数据库被MongoDb.Driver.Database

问题如下: 当我试图查询Get方法不带任何参数 - localhost/api/accounts - 它返回的所有帐户(意) 当我使用跳过:localhost/api/accounts?$skip=n - 它跳过n,返回休息项目 (如预期太) 但是,localhost/api/accounts?$top=1返回所有账户,而不是一个。

我该如何处理?

回答

1

的问题是在[可查询(RESULTLIMIT = 50)〕:

它和$top=1一起产生以下表达式: coll.Take(1).Take(50)返回不为1,但50(或在集合中的所有元素,在情况下,如果元素少于50)。
顺便说一下,Database.GetCollection<A>("A").AsQueryable().Take(1).Take(50) - 不再返回1个元素。
这看起来像臭虫MongoDbDriver

0

使用与$orderby

localhost/api/accounts?$top=1&$orderby=... 
相关问题