I have a person object, which can have unlimited number of first names. So the first names are another object.
ie
person --- name
--- name
--- name
What I want to do is write an nhiberate query using which will get me a person who has certain names.
so one query might be find someone whose names are alison and jane and philippa, then next query may be one to find someone whose names are alison and jane.
I only want to return people who have all the names I'm search on. So far I've got
ICriteria criteria = session.CreateCriteria(typeof (Person));
criteria.CreateAlias("Names", "name");
ICriterion expression = null;
foreach (string name in namesToFind)
{
if (expression == null)
{
expression = Expression.Like("name.Value", "%" + name + "%");
}
else
{
expression = Expression.Or(
expression,
Expression.Like("name.Value", "%" + name + "%"));
}
}
if (expression != null)
criteria.Add(expression);
But this is returning every person with ANY of the names I'm searching on, not ALL the names.
Can anyone help me out with this? Thanks!