I have this object :
public class Ledger
{
public virtual Person Client { get; set; }
// ....
}
The Ledger table joins to the Person table via one of three possible tables : Bill, Receipt or Payment.
So we have the following tables :
Ledger LedgerID PK
Bill BillID PK, LedgerID, ClientID
Receipt ReceiptID PK, LedgerID, ClientID
Payment PaymentID PK, LedgerID, ClientID
If it was just the one table, I could map this as :
Join ( "Bill", x =>
{
x.ManyToOne ( ledger => ledger.Client, mapping => mapping.Column ( "ClientID" ) );
x.Key ( l => l.Column ( "LedgerID" ) );
} );
This won't work for three tables. For a start the Join performs an inner join. Since there will only ever be one of Bill, Receipt or Payment - an inner join on these tables will always return zero rows.
Then it would need to know to do a Coalesce on the ClientID of each of these tables to know the ClientID to grab the data from.
Is there a way to do this? Or am I asking too much of the mappings here?