7
I have a property of an entity that’s like DateTime?
and in SQL Server is of the type datetime
also. I need to make a query that sorts by date, but without considering the time, because in this specific view it will not show the time. Then sort by code.
Make two ordinations I get with ThenBy
, I don’t know how to ignore the time.
var query = contexto.Contas.OrderBy(c => c.Data).ThenBy(c => c.Codigo);
Suppose this data
001 | 22/12/2016 13:25
002 | 22/12/2016 11:25
003 | 22/12/2016 12:25
Today is displayed like this:
002 | 22/12/2016
003 | 22/12/2016
001 | 22/12/2016
But it should be:
001 22/12/2016
002 22/12/2016
003 22/12/2016
I had a similar case using the
nHibernate
, solved by doing this...OrderBy(c => c.Data.HasValue ? c.Data.Date : ((DateTime?)null)))
,– Marco Giovanni
Complementing what @Marcogiovanni said. http://stackoverflow.com/a/6121309/2957607
– Aron Linhares