What I want to achieve is that to retrieve all data from the database, as of now I know that I need to replace
SingleOrDefault
with something else and can I know what is the method below called ? I don't think is 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));
}
Solution
[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));
}
Try using .Where(x => x.WWPED <= futureDate)
that will get you the entities, you can then map them into the desired format for returning as result. This might be easier using linq.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.