I’m having trouble with something that (I think) should be simple, but can’t find any clear info.
In the scenario where I have three tables, describing a domain where a person can have more than one job:
Person – has PersonId, Name
Job – has JobId, JobName
PersonJob – has PersonId, JobId, YearsOfEmployment
Note: In my object model, I have entities representing each table. I have that third entity to represent the Person/Job relationship since there is useful metadata there (YearsOfEmployment) and is not just a simple join table.
So, if I knew the PersonId and the JobId, is there a simple way for me to use the session and return an object matching those Ids?
Or, put a different way, since I already know the primary keys is there a brain-dead, simple way I can turn the SQL ‘SELECT YearsOfEmployment FROM PersonJob WHERE PersonId=1 AND JobId=1’ into something like:
var keys = new {PersonId=1, JobId=2};
PersonJob obj = Session.Get<PersonJob>(keys);
BTW: maps would look something like this:
<class name='Person' table='dbo.Person' lazy='true'> <id name='PersonId'> <generator class='native'/> </id> <property name='Name'/> </class> <class name='Job' table='dbo.Job' lazy='true'> <id name='JobId'> <generator class='native'/> </id> <property name='JobName'/> </class> <class name='PersonJob' table='dbo.PersonJob' lazy='true'> <composite-id> <key-property name='PersonId'></key-property> <key-property name='JobId'></key-property> </composite-id> <property name='YearsOfEmployment'/> </class>
Well, I answered my own question. I think posting your problem is almost as cathartic as talking it out with someone. If I were to make the composite-id of PersonJob a component or class, i.e.
Then I can simply do this:
cool. hope this helps anyone else figuring this out …