CodePaste Logo
New Snippet New Snippet Recent Snippets Recent Snippets My Snippets My Snippets Web Code Search Snippets Search
Sign inor Register
Language: C#

When HQL does not support TOP keyword

627 Views
Copy Code Show/Hide Line Numbers
   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:   
by afsharm
  November 01, 2009 @ 2:24am
Tags:

by afsharm    January 06, 2010 @ 9:40pm

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

Add a comment


Report Abuse
brought to you by:
West Wind Techologies



If you find this site useful and use it frequently please consider making a donation to support this free service.
Donate