I am trying to reproduce this SQL query in NH:
select vehicle.Id, price.Price
from vhc.Vehicle vehicle
left outer join vhc.VehiclePrice price on vehicle.Id = price.VehicleId
and price.VehiclePriceTypeId = 1
where price.Id is null or price.VehiclePriceTypeId = 1
order by price.Price
The important part is the second join criteria. I want to see all Vehicles, regardless of whether they have a price, but if they have any prices, I want to select the price of type 1. Removing that second join criteria means that it excludes all vehicles that only have prices of types 2, 3, etc. That's not ok.
Approaches I've tried:
Adding a global filter on the VehiclePrice object to filter only on VehiclePriceType = 1 but it puts it on the Where, not on the Join, so no luck there.
Adding a SubQuery for prices with type 1, but, again, it applies it on the Where, not on the Join.
Other join types -- Full, Right... don't seem to make sense here.
It's a common problem, just haven't found the solution yet. Any thoughts?