Language: C#
When HQL does not support TOP keyword
1: string res = string.Empty; 2: 3: try 4: { 5: IQuery query = session.CreateQuery("select ao.CostCenterAccount from " + 6: "AssetObservation as ao where ao.Asset.ID=:KEY " + 7: "and ao.Date<:DATETIME order by Date asc"); 8: query.SetInt64("KEY", asset.Id); 9: query.SetDateTime("DATETIME", dateTime); 10: 11: //SetFirstResult and SetMaxResults are used instead of "SLECT TOP N" 12: object obj = query.SetFirstResult(0).SetMaxResults(1).UniqueResult(); 13: if (obj != null) 14: res = Convert.ToString(obj); 15: } 16: catch (Exception ex) 17: { 18: bool rethrow = ExceptionPolicy.HandleException(ex, Constants.Exception.ExceptionPolicy.ServiceExceptionPolicy); 19: if (rethrow) 20: throw; 21: } 22: return res; 23:
Tags:
Report Abuse
Subscribe
Discuss
What's new
What is it
New Snippet
Recent Snippets
My Snippets
Web Code
Search


یک بار دیگه از این کد مفید استفاده کردم!