string query = "(select count(*) from UC_Message m where m.IsDeleted = 0 and this_1_.ChannelCommunication = m.ChannelCommunication and ((this_1_.DirectionMessage = 1 and this_1_.\"From\" = m.\"From\") or ((this_1_.DirectionMessage = 2 and this_1_.\"To\" = m.\"To\")) )) as t_count";
criteria.AddOrder(Order.Desc(Projections.SqlProjection(query, new string[] { "t_count" }, new IType[] { NHibernateUtil.Int32 })));