I have an IList<string> named codes storing the code values for which I want to perform a query to retrieve entities from the database.
I have to retrieve all entities for which the code meets the SQL WHERE conditions:
Code = 'someCode' OR Code LIKE 'someCode/%'
where ‘someCode’ is successively each code in the IList<string> codes.
Example condition:
Code = 'someCode0' OR Code LIKE 'someCode0/%'
OR Code = 'someCode1' OR Code LIKE 'someCode1/%'
OR Code = 'someCode2' OR Code LIKE 'someCode2/%'
.
.
.
OR Code = 'someCodeN' OR Code LIKE 'someCodeN/%'
Where N is codes.Count – 1.
I tried using CreateSQLQuery and generated the above string but I got an exception which came from a bug which was fixed in a later version (using NHibernate 1.2.1.4000).
Thanks for answers!
Using HQL you can use something like this:
Where someCodes is your
IList<String>;Here are some other good HQL examples to guide you.