Reputation: 620
I am trying to show deal.type as decending order by date but I cannot get the result to show in Descending order.
[Authorize(Roles = "admin")]
[HttpGet]
[Queryable(PageSize = 10)]
public HttpResponseMessage Get([FromUri] Query query)
{
var data = db.database_ICs.AsQueryable();
if (query.price_type != null)
{
data = data.Where(c => c.Cover == query.price_type);
}
if (query.deal_type != null)
{
data = data.Where(c => c.Type == query.deal_type)
.OrderByDescending(c => c.UploadDate);
}
if (query.startDate != null)
{
data = data.Where(c => c.UploadDate >= query.startDate);
}
if (query.endDate != null)
{
data = data.Where(c => c.UploadDate <= query.endDate);
}
if (!data.Any())
{
var message = string.Format("No data was found");
return Request.CreateErrorResponse(HttpStatusCode.NotFound, message);
}
return Request.CreateResponse(HttpStatusCode.OK, data);
}
Any help would be very much appreciated.
Upvotes: 1
Views: 89
Reputation: 1141
Please, try change this:
[Queryable(PageSize = 10)]
For this:
[Queryable(PageSize = 10, EnsureStableOrdering = false)]
More informations here. Hope that helps!
See ya!
Upvotes: 1