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?
If I did something like:
ICriteria criteria = Session.CreateCriteria<Invitation>()
.Add(SqlExpression.CriterionFor<Invitation>(i => i.Person == person));
return criteria.List<Invitation>();
then that only gives me a list of Invitation objects, through which I'd have to loop to get the Event for each one. I'd rather have a list of Event objects from the query. How do I do this?