I have 3 tables. Job, Person, JobPerson (=association table)
When I need all jobs made by certain person, I write this:
ICriteria critMain = session.CreateCriteria(typeof(Job));
Disjunction orMain = new Disjunction();
critMain.Add(orMain); //there will be another conditions later
DetachedCriteria subquery = DetachedCriteria.For(typeof(JobPerson));
subquery.Add(Expression.Eq("IdPerson", requestedPersonId));
subquery.SetProjection(Projections.Property("IdJob"));
orMain.Add(Subqueries.PropertyIn("IdJob", subquery));
IList aaaaa = critMain.List();
It works OK, but I have to declare association class JobPerson (which maps the association table with IdJob and IdPerson)
My question is: Is it really necessary to write the association Class JobPerson or is there any simplier way???
I have to add, that I work with Criterias.
Thanks for any answer.
|