How you have ur mappings setup is kinda crucial.

If you want the employee always loaded with the committee (i.e. -
every time you session.load<committee>(id), you want the query to be a
join), then you need to have in the committee mapping constructor:
 base.references<employee>(x=>x.Employee)
    .keycolumn("empidcolname")
    .fetch.join();

I'm not exactly sure on that syntax (specifically the .references &
keycolumn. It might be association & foreignkey?) ..  But that should
be pretty close.

You probably don't want the employee having a bi-directional reference
back to the committe (for employee re-use in other associations.
depends on ur model tho. It could lead to some nasty n+1 sql if
committee has other collections,dependencies), so u wont need an
association/reference in the employee.

On 9/29/11, Influently NHiberater <[email protected]> wrote:
> How does an ORM framework handle joins like what we do in plain SQL?  Is it
> the case that an ORM framework doesn't explicitly join two or more tables?
>
> Suppose I have the following two tables in my database:
>
> Employees
> {
>     Eid int primary key,
>     FirstName varchar(20),
>     LastName varchar(20)
> }
>
> Committees
> {
>     Cid int primary key,
>     Name varchar(50),  <--- This is the committee name.
>     ChairId int references Employees.Eid
> }
>
> And I have my POCO classes, EmployeeMap and CommitteeMap defined.
>
> Now how can I use Linq or FluentNHibernate Linq to get something like what
> the following SQL query would give me?
>
> SELECT e.FirstName, e.LastName, c.Name
> FROM Employees e
> INNER JOIN Committees c
> ON e.Eid = c.ChairId
>
> All FluentNHibernate examples I've seen online query only one table, and
> which is pretty simple and straightforward, but in reality, we rarely query
> only one table.
>
> Can anyone give me a working example or a pointer to such a thing?  Thank
> you.
>
> --
> You received this message because you are subscribed to the Google Groups
> "Fluent NHibernate" group.
> To view this discussion on the web visit
> https://groups.google.com/d/msg/fluent-nhibernate/-/gqPPQqqV7D0J.
> To post to this group, send email to [email protected].
> To unsubscribe from this group, send email to
> [email protected].
> For more options, visit this group at
> http://groups.google.com/group/fluent-nhibernate?hl=en.
>
>

-- 
Sent from my mobile device

------
Joe Brockhaus
[email protected]
------------

-- 
You received this message because you are subscribed to the Google Groups 
"Fluent NHibernate" group.
To post to this group, send email to [email protected].
To unsubscribe from this group, send email to 
[email protected].
For more options, visit this group at 
http://groups.google.com/group/fluent-nhibernate?hl=en.

Reply via email to