Hopefully someone with some nHibernate experience will chime in, but I think the easiest approach might be to create your Invoice object with a single InvoiceableItems collection. That collection would be created from 2 internal collections of Vehicles and TextJobs. Vehicle and TextJob classes would each implement the InvoiceableItem interface:
Code:
<?xml version="1.0" encoding="utf-8" ?>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.0">
<class name="LogisticsManagement.Core.Components.Invoice, Logistics" table="Invoices">
<!-- chopped bits out here -->
<bag name="InvoiceVehicles" cascade="all" lazy="true">
<key column="invoiceID" />
<one-to-many class="LogisticsManagement.Core.Components.Vehicle, Logistics" />
</bag>
<bag name="InvoiceTextJobs" cascade="all" lazy="true">
<key column="invoiceID" />
<one-to-many class="LogisticsManagement.Core.Components.TextJob, Logistics" />
</bag>
<!-- chopped bits out here -->
</class>
</hibernate-mapping>
You'd need to write the code that combined the 2 internal collections into a single coherent collection, and in addition you'd need to detect the type of object being added, but this approach would keep the mapping simple, and isolate the higher level code from the fact that the objects are coming from 2 different tables. It would only need to know that the collection can contain n types of items, not how they are stored.
e.g. (not tested or anything):
Code:
public void AddInvoiceItem(InvoiceableItem item)
{
if (item is InvoiceVehicle)
{
InvoiceVehicles.Add((InvoiceVehicle)item);
}
else if (item is InvoiceTextJob)
{
InvoiceTextJobs.Add((InvoiceTextJob)item);
}
}
I'm not going to try to include sample code for the collection, but I'd think that creating an iterator for your class would be the easiest way (at least easiest for the consuming code, and since you're only going to write the collection once and likely consume it multiple times...).
I don't think this approach should be too complicated.
Colin