2011-09-30 80 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函數將序列化查詢並嚴重傷害查詢性能。 –

相關問題