我想要实现的是从数据库中检索所有数据,截至目前我知道我需要替换
的SingleOrDefault
用别的东西,我可以知道下面叫做的方法是什么?我不认为是linq?
[Route("api/{AuthCode}/LoadWorkers")]
public Task<HttpResponseMessage> GET(String Authcode)
{
DateTime futureDate = new DateTime();
futureDate = DateTime.Now.AddDays(90);
worker result = new worker();
result = KKDB.workers.SingleOrDefault(p => p.WWPED <= futureDate);
return Task.FromResult(Request.CreateResponse<worker>(HttpStatusCode.OK, result));
}
解决方案
[Route("api/{AuthCode}/LoadWorkers")]
public Task<HttpResponseMessage> GET(String Authcode)
{
DateTime futureDate = new DateTime();
futureDate = DateTime.Now.AddDays(90);
var result = KKDB.workers.Where(x => x.WWPED <= futureDate);
return Task.FromResult(Request.CreateResponse<IQueryable<worker>>HttpStatusCode.OK,result));
}
答案 0 :(得分:0)
尝试使用可以获取实体的.Where(x => x.WWPED <= futureDate)
,然后您可以将它们映射到所需的格式以便返回结果。使用linq可能会更容易。