Friday, March 9, 2012

Expression.Like for numbers?

Hi,

Is it possible to search in columns with a number datatype (I'm using an MS SQL database with bigint columns) with the ICriterion Expression.Like?

Normally the Expression.Like is used for varchar columns. However, if there's a bigint column with the value 167829 I want to search for example on %678%.

Cheers,

koekie

You can cast the BIGINT to varchar ad test that like:

WHERE CONVERT(VARCHAR(20), ColName) LIKE '%678%'

|||

In other words, something like this:

Expression.Sql("CONVERT(VARCHAR(20), {alias}.ColName) LIKE ?", "%678%", NHibernateUtil.String )

|||

Cool, thanks a lot.

No comments:

Post a Comment