I cannot get DetachedCriteria to work properly after nesting several times, the reason is that DetatchedCriteria can only access items with an alias one level higher.
The following steps do not work, for example:
var secondNestedCriteria = DetachedCriteria.For<Baz>("baz")
.SetProjection(Projections.Id())
.Add(Restrictions.EqProperty("baz.FooName", "foo.Name")
.Add(Restrictions.EqProperty("baz.BarName", "bar.Name");
var firstNestedCriteria = DetachedCriteria.For<Bar>("bar")
.SetProjection(Projections.Id())
.Add(Restrictions.EqProperty("bar.FooName", "foo.Name")
.Add(Subqueries.Exists(secondNestedCriteria);
var criteria = Session.CreateCriteria<Foo>("foo")
.Add(Subqueries.Exists(firstNestedCriteria)
.List<Foo>();
Does anyone know a workaround that is not related to using HQL?
source
share