Răzvan Flavius Panda
Răzvan Flavius Panda

Reputation: 22116

How to query using criteria to obtain all objects whose propriety is different than any string value in a list?

Having:

How can I query using criteria to obtain all Person instances who have a Name which is not found in the names list?

Thanks for answers!

Solution:

var myQuery = session.CreateCriteria(typeof(Person))
                     .Add(Expression.Not(Expression.In("Name", names));

Upvotes: 1

Views: 60

Answers (2)

alfdev
alfdev

Reputation: 1049

var ps = from p in persons
    where !list.Contains(p.Name)
    select p;

Try this.

Upvotes: 0

Polity
Polity

Reputation: 15130

Your looking for an In expression, see: Nhibernate HQL where IN query

That would make your particular case something like:

ActiveRecordMediator<Person>.FindAll(Expression.Not(Expression.In("Name", names))) 

Upvotes: 2

Related Questions