How do I query through a many-to-many relationship using NHibernate Criteria and Lambda Extensions?

Posted by Brian Kendig on Stack Overflow See other posts from Stack Overflow or by Brian Kendig
Published on 2010-03-11T18:49:48Z Indexed on 2010/03/11 18:54 UTC
Read the original article Hit count: 231

Filed under:
|
|

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?

© Stack Overflow or respective owner

Related posts about nhibernate

Related posts about criteria