我试图按日期将deal.type显示为降序,但我无法将结果显示为降序。
[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);
}
非常感谢任何帮助。
答案 0 :(得分:1)
请尝试更改此内容:
[Queryable(PageSize = 10)]
为此:
[Queryable(PageSize = 10, EnsureStableOrdering = false)]
更多信息here。 希望有所帮助!
见啊!