This one has me stumped and thought I would pose it to the SO community for help.
A user wants to select all orders that start with a certain ID, example:
123 would return 123, 12345, 1238790, etc. ID is an int column however.
I’m using nHibernate and my line currently is:
criteria.Add(Restrictions.Eq("Id", itemId));
but that’s only going to return me 123. I can do a Restrictions.Like, but that converts to a SQL LIKE clause and that won’t work on an int col.
Any ideas?
EDIT: Sorry, the DB is SQL Server 2008
Unfortunately, you didn’t specify what database you’re using (SQL is just the query language….), but if you’re on SQL Server (the Microsoft RDBMS product), then you could create a computed column of type
VARCHAR(15)to hold a string representation of yourINT, and then just search on that….Whether that really makes business sense, is a totally different story….. (I agree with Oded and Matt Ball…)
But since that’s a string column now, you should be able to use your
Restrictions.Likeapproach in NHibernate as you mention.