Hi
Given a list of strings I want to retrieve all items whose names contain one of the given strings.
for example- given {“foo”, “kuku”} I want to retrieve the employees “Corfoo”, “kuku maluku” and “kukufoo”.
I’ve tried the following, but got a null-reference exception(?)
query.Where(u => values.Any(v=> u.FullName.Contains(v)) );
The following produced a ‘Lambda expression not in scope’ exception.
query.Where(u => (values.Count(v => u.FullName.Contains(v)) > 0) );
any idea how this can be done?
I was thinking along the lines of iterating over the values collection and adding a new condition for each element.
problem is- the .Where() function is a conjunction (AND) and I need disjunction (OR)…
(I’m using nH 2.1.2 with Linq provider; hadn’t tried this on nH3.0 yet…)
If you are not limited to the Linq provider but also open to the ICriteria API, I suggest using the following:
I think trying that in NHibernate.Linq might be harder if not impossible. With NH 3.0 you could use QueryOver, which would get rid of the magic strings.