2011-09-30 127 views
0

我试图在HQL中选择不同日期时间字段。在HQL中没有时间的独特日期时间字段

select distinct CreatedDate from ClaimFile order by CreatedDate DESC 

任何想法我怎样才能得到明确的日期没有时间。现在它不可能随着时间而变得清晰。

感谢

回答

0

我只能想到几个选项:

  1. 注册在你的方言CustomSQLFunction并用它来 日期时间格式化为一个日期。
  2. 创建一个ComputedColumn(sql服务器),它只是剥离时间。将它作为只读添加到映射并使用它。
  3. 只是回到普通的SQL,因为你似乎只需要一个日期列表而不是对象。
  4. property映射中使用formulaProperty Mapping Element Explained <property name="CreateDate" formula="cast(convert(varchar(10),CreateDate,103) as datetime)" />
+0

你能给我发一个例子吗?我怎样才能在方言中注册转换sql函数 – user585014

+0

这里有几个链接让你开始:http://ayende.com/blog/1720/using-sql- functions-in-nhibernate http://nhforge.org/blogs/nhibernate/archive/2009/03/13/registering-freetext-or-contains-functions-into-a-nhibernate-dialect.aspx –

+0

还要记住,使用SQL函数将序列化查询并严重伤害查询性能。 –

相关问题