我在Entity Framework Code First上编写了数据库,并在我的Web Api中使用它
如果我的表中有超过400条记录,我就无法获得任何记录,但如果我的记录少于400条,那么一切正常。
这是我获取记录的代码:
public IEnumerable<Contact> Get(int pageSize, int pageIndex)
{
return db.Set<Contact>().OrderBy(e => e.Id).Skip(pageSize * pageIndex).Take(pageSize).AsParallel<Contact>().AsOrdered();
}
获得1条记录的另一种方法也不起作用。
public Contact Get(int id) { return db.Set<Contact>().Find(id); }
我注意到为响应增量添加了新的记录时间
当我有100个响应的记录时间是4秒,如果我有200秒10秒。
你能解释一下我做错了什么吗?
编辑代码
private ICompanyService companyService;
public CompaniesController(ICompanyService companyService)
{
this.companyService = companyService;
}
//// GET api/companies
public IHttpActionResult Get([FromUri]int SizePage=100, [FromUri]int Page=1)
{
return Ok(companyService.Get(SizePage, Page));
}
//// GET api/companies/5
public IHttpActionResult Get([FromUri]int id)
{
return Ok(companyService.Get(id));
}