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.  [ 2 posts ] 
Author Message
 Post subject: Type Error Using LikeExpression
PostPosted: Wed Feb 04, 2009 3:23 am 
Newbie

Joined: Sat Jun 10, 2006 10:24 am
Posts: 16
Hibernate version: 2.0.1 GA

Hi Nhibernate Experts!

I have a quick question, in my application I have a series of forms where the user can build a simple query which then gets passed to NH. The problem is the user can might build a query like this

ItemCount Contains '%328%' (Yes unlikely, but still valid SQL)

But Nh thorws an error:

"Failed to convert parameter value from a String to a Int32."

because the property Itemcount is a int, my question is: is there a way to turn off the type safety checking in the criteria or have it not check the type of the field its comparing aginst?

Thanks!
Maxus


Top
 Profile  
 
 Post subject:
PostPosted: Thu Feb 05, 2009 8:47 pm 
Newbie

Joined: Sat Jun 10, 2006 10:24 am
Posts: 16
Hi People,

I have found a work around but it appears to be really kludgy..

Code:

NHibernate.SqlCommand.SqlStringBuilder SQLQuery = new NHibernate.SqlCommand.SqlStringBuilder();
SQLQuery.Add(string.Format("{0} Like ", "FieldName"));
SQLQuery.AddParameter();

Criteria = new SQLCriterion(SQLQuery.ToSqlString(), new object[] { "%" + "FieldValue" + "%" }, new IType[] {NHibernate.NHibernateUtil.String });



Anyone know of a better way of doing this?

Thanks!
Maxus


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