In my project, Lines
can be grouped and a Group
has a type which can be either Crossing
(1) or Parallel
(2). I need to find all lines which has at least one group of a specified type (in this case, 1). The Id of a given line can be either on column LineA
or LineB
of a group. Here is where i got so far:
Criteria crit = session.CreateCriteria(typeof(Line), "ln");
DetachedCriteria count = DetachedCriteria.For<Group>()
.SetProjection(Projections.CountDistinct("Id"))
.Add(Expression.Or(
Expression.EqProperty("LineA", "ln.Id"),
Expression.EqProperty("LineB", "ln.Id")))
.Add(Expression.Eq("GroupTypeId", 1));
crit.Add(Subqueries.Gt(0, count));