I am trying to sorty data using date column but the column is sorting as string not as date. how to solve this problem?
Code:
var projection = Projections.SqlFunction("lower", NHibernateUtil.String,Projections.Property("datecolumn1"));
if(order="desc")queryOver = queryOver.OrderBy(projection).Desc;
else queryOver = queryOver.OrderBy(projection).Asc;
Result:(sorted by ascending)
8/7/2012 5:34 AM
11/7/2012 7:21 AM
11/7/2012 7:21 AM
11/7/2012 7:21 AM
11/7/2012 7:21 AM
8/27/2012 9:35 AM
The snippet above shows that the there is a
stringprojection. So the result is sorted as a set of string values. (and that could lead to different results dependent on sql server defaultDateTime.ToStringformat).To sort it by date add a different projection:
Now it should be ordered by native SQL Server
DateTimetype