A Project can have many Parts. A property on Part is Ipn, which is a string of digits.
- Project "A" has Parts "1", "2", "3"
- Project "B" has Parts "2", "3", "4"
- Project "C" has Parts "2"
- Project "D" has Parts "3"
I want to find all Projects that have all of the specified parts associated with it. My current query is
var ipns = new List<String> { "2", "3" }
var criteriaForIpns = DetachedCriteria
.For<Part>()
.SetProjection(Projections.Id())
.Add(Expression.In("Ipn", ipns));
_criteriaForProject
.CreateCriteria("Ipns")
.Add(Subqueries.PropertyIn("Id", criteriaForIpns));
This gives me back all Projects that have any of the parts, thus the result set is Projects A, B, C, and D.
The SQL where clause generated, looks something like
WHERE part1_.Id in (SELECT this_0_.Id as y0_
FROM Parts this_0_
WHERE this_0_.Ipn in ('2' /* @p0 */,'3' /* @p1 */))
My desired result would only be Projects A and B. How can I construct the NHibernate criteria to get the result set that I need?
The number of parts I search on can vary, it can be n number of parts.