-->
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.  [ 5 posts ] 
Author Message
 Post subject: Like Criteria comparing integer to string
PostPosted: Fri Sep 21, 2007 3:30 pm 
Newbie

Joined: Wed May 02, 2007 9:32 am
Posts: 17
Hi,

I was wondering if this was possible - I have an Order object with an orderId (int) of 1708912 I would like to be abel to do a "like" search on it, for example finding all orders that contain "7089".

The code I have is failing:

Code:
            ICriteria crit = NHibernateSession.CreateCriteria(typeof(Core.Order));
            crit.Add(Expression.Like("OrderId", "%" + orderNumber + "%"));
            IList<Core.Order> orders = crit.List<Core.Order>();
            return orders;


Is there a (simple) way to do this?
Thanks
Joe


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 17, 2008 8:18 am 
Newbie

Joined: Sat Jun 23, 2007 5:36 pm
Posts: 7
Have you found a solution for this, or does anybody have an idea?

I also tried to use the MatchMode, however, suddenly a string is expected instead of an object.... I really needs this. Hope someone can help.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 17, 2008 9:03 am 
Expert
Expert

Joined: Tue Aug 23, 2005 5:52 am
Posts: 335
Like only works on strings columns as far as I know, so if you want to use like you need to provide a string. If you have an int you can always cast it to string before you pass it to the like, I would think.

Cheers,

Symon.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 24, 2008 7:26 am 
Newbie

Joined: Sat Jun 23, 2007 5:36 pm
Posts: 7
I eventually did this by creating a derived property on the entity which is a string representation of the int column. A pretty simple and straitforward fix in the end. Works like a charm.


Top
 Profile  
 
 Post subject:
PostPosted: Thu Jan 24, 2008 7:27 am 
Newbie

Joined: Sat Jun 23, 2007 5:36 pm
Posts: 7
I eventually did this by creating a derived property on the entity which is a string representation of the int column. A pretty simple and straitforward fix in the end. Works like a charm.


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 5 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.