I am trying to build the following association in NHibernate (the base Entity class contains an Id property, it and the attributes are from S#arp Architecture)
public class Terminal : Entity {
public virtual string Name { get; set; }
}
public class Order : Entity {
[NotNull]
public virtual Terminal Terminal { get; set; }
}
Where the data on order is stored in ORDERS and data on terminals in stored in the TERMINALS tables. The problem is that there is no direct link between the two tables. If I had an id for ORDERS.ORDER_ID I would fetch the corresponding TERMINALS row with the following SQL.
select t.*
from ORDERS o
inner join cust_prod cp on (o.CUST_PROD_ID = cp.CUST_PROD_ID)
inner join customer_terminal ct on (cp.CUSTOMER_TERMINAL_ID = ct.CUSTOMER_TERMINAL_ID)
inner join terminal t on (ct.TERMINAL_ID = t.TERMINAL_ID)
where o.ORDER_ID = :p_order_id
How do I map this in NHibernate? Preferably how do I map this in Fluent NHibernate but I think I could figure it out from the XML. Also, given that the legacy database I'm working with is full of chains like this are there any best practices suggestions?