How do I query through a many-to-many relationship using NHibernate Criteria and Lambda Extensions?
- by Brian Kendig
In my database I have a Person table and an Event table (parties, meetings, &c.). This many-to-many relationship is represented through an Invitation table. Each Person can have many Invitations. Each Event can also have many Invitations.
If I want a list of Events to which a Person is invited, I can use this HQL query:
IQuery query = Session.CreateQuery("SELECT i.Event from Invitation i where i.Person = :p");
query.SetParameter("p", person);
return query.List<Person>();
How would I write this query with NHibernate criteria and Lambda Extensions?