Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NHibernate - Implement "NOT IN" query using ICriteria

I've started getting to grips with NHibernate. I'm trying to perform a query that selects all records from a table but with an exclusion filter list of IDs, eg. get me all Products except these ones with these ID values.

Normally in direct T-SQL I'd pass in the IDs to be excluded into a NOT IN clause like so.

SELECT *
FROM Products
WHERE ProductId NOT IN (1,5,9,23,45)

How do I do this in NHibernate using either ICriteria or HQL (but preferably ICriteria)?

like image 289
Sunday Ironfoot Avatar asked Jul 22 '09 22:07

Sunday Ironfoot


1 Answers

Try

.Add(Expression.Not(Expression.In("ProductID", new int[] { 1, 5, 9, 23, 45 })))
like image 95
Spencer Ruport Avatar answered Oct 23 '22 06:10

Spencer Ruport