If I have two entities 'Parent' and 'Group' with a many-to-many
relation without an explicit mapping entity:
public class Parent
{
public virtual ICollection<Group> Groups { get; set; }
}
public class Group
{
public virtual ICollection<Parent> People { get; set; }
}
I would like to query for all Parents that have no groups.
Using HQL I can do:
var results = Session.CreateQuery("from Parent p where not exists
elements(p.Groups)").List();
Using Linq I can do:
var results = Session.Query<Parent>().Where(p => p.Children.Count() ==
0).ToList();
However, I using QueryOver syntax, is there any simpler way than doing
the following:
Parent parentAlias = null;
var subQuery = QueryOver.Of<Group>()
.Inner.JoinQueryOver<Parent>(g
=> g.People)
.Where(p => p.Id ==
parentAlias.Id)
.Select(p => p.Id);
var results = Session.QueryOver(() => parentAlias)
.WithSubquery.WhereNotExists(subQuery)
.List();
Any suggestions? Thanks!
--
You received this message because you are subscribed to the Google Groups
"nhusers" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to
[email protected].
For more options, visit this group at
http://groups.google.com/group/nhusers?hl=en.