1
I have a field that stores DATETIME
in my database. However I need to ignore the time of this field when I am ordering for it.
The following code makes my search:
public virtual async Task<(List<TModel>, int)> FindAsync(IQueryable<TModel> query, int pageNumber = 1, int pageSize = 20, string[] sortExpression = null, Expression<Func<TModel, object>> includes = null)
{
query = Includes(includes, query);
query = SetFilterAll(query);
var count = await query.CountAsync();
query = Sort(sortExpression, query);
query = Pagination(pageNumber, pageSize, query);
return (await query.ToListAsync(), count);
}
I would like to send in the parameter sortExpresion
something like,
CAST(meu_campo_date AS DATE)
So that in the end it would execute an SQL similar to this:
SELECT * FROM MinhaTabela ORDER BY CAST(meu_campo_date AS DATE) DESC
In that case you don’t answer me, Keven. I need that there is time that ORDER BY will execute my SQL query to use only the date. The critical point is that I need to do this through the entityframework sending by the extension method of the Iqueryable interface.
– Daniel Silva
How did you not put the method
sort
i have no way of knowing exactly how the ordering was implemented, but it would be something likequery.OrderBy(x => x.SuaPropriedadeData.Date)
. In this way the Entityframework itself would mount the ordering of the query.– Keven Carneiro