-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 
Author Message
 Post subject: Suggestion: allow Order class to be inherited
PostPosted: Wed May 23, 2007 3:19 pm 
Newbie

Joined: Tue May 15, 2007 3:53 pm
Posts: 9
I'm trying to use a criteria search, and list the results alphabetically. Unfortunately, the fields have random whitespace and html fragments, as well as mixed case. So, what I need to do is call
Code:
ORDER BY lower(ltrim(strip_html(field))) ASC


After searching these forums, someone in the Java forum posted about simply extending the order class. I did that, only to realize that in C#, I can't override the ToSqlString method.

So, my suggestion:

instead of defining Order as:
Code:
   public class Order
   {
      private bool _ascending;
      private string _propertyName;

      public string ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
      {
      }
   }


could the next revision define it as this?
Code:
   public class Order
   {
      protected bool _ascending;
      protected string _propertyName;

      public virtual string ToSqlString(ICriteria criteria, ICriteriaQuery criteriaQuery)
      {
      }
   }


Oh, and is there any way to do this without having to add a dozen SortFieldX entries in my mapping files?


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 6:11 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
I'm not sure what you mean by the fields containing whitespace and html fragments, but if you have field names mapped that aren't sql friendly you can use backticks in your mapping to indicate that the field name should be "wrapped" in the generated SQL to make sure it's legal.

For example if you have a field name "my field" in an MS SQL db you need to wrap it in square brackets to make it legal in an sql statement:

Code:
eg: SELECT [my field] from sometable


If you do your mapping with the backticks `my field` in your mapping file NHibernate will add the square brackets (for MS SQL, or whatever is valid for your chosen dialect).

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 9:34 am 
Contributor
Contributor

Joined: Wed May 11, 2005 4:59 pm
Posts: 1766
Location: Prague, Czech Republic
Submit your request to JIRA please.


Top
 Profile  
 
 Post subject:
PostPosted: Thu May 24, 2007 11:00 am 
Newbie

Joined: Tue May 15, 2007 3:53 pm
Posts: 9
merge_s.rottem wrote:
I'm not sure what you mean by the fields containing whitespace and html fragments


I mean I have a Product table, and in the ProductName field, I have values like " <b><i>Company's</i> Cool Product&reg;</b>"

this would be sorted at the top due to leading whitespace and html tags, when it should be sorted as "company's cool product", right before "company's dumb product", and right after "company's awesome product"


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 4 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.