I don't think the query you gave will work -- if there are tradeprices for a given trade that are both before and after the effective date (such data for those kinds of tables doesn't make sense to me, but this issue is about left joining to any one-to-many collection) your NOT EXISTS clause would eliminate that trade.
Let's look at a clearer example. Say you want to query all contacts and their cell phone number. If they don't have a cell phone, you still want the contact selected. You want to do this in one query, no massaging or filtering the result set afterwards in code.
Once your query contains this much:
Code:
SELECT Contact.Name, CellPhone.Number
FROM Contact AS Contact
LEFT JOIN Contact.Phones AS CellPhone
WHERE CellPhone.Type = 'Cell'
then if a particular contact has one or more phones but none are cell phones, you will get no row back for that contact at all. I'm not aware of any possible additional logic you could put into the WHERE clause to tell it that the join should still succeed (i.e. that the contact should still be selected) but that the selected properties from the CellPhone should all be NULL. A far as I know, LEFT JOIN will only return a NULL substitute if nothing matches what is in its ON clause; if something does match what is in the ON clause (and using NHibernate HQL, it's currently only what is set up in the mapping), then it works like a regular JOIN, and particular phone row(s) are either joined to or the driving entity (at the start of the FROM clause) is not selected.
I imagine that if joined rows do exist but none match your criteria, using a subselect you could join to the top first phone row (which has the "wrong" data) and then map everything you select in the SELECT clause with CASE statements from "wrong" values to NULLs. Unfortunately I don't think you can have CASE statements in the SELECT clause in HQL, or even select a literal NULL. Even if you could, this would be a very confusing workaround.
Something like the above query with a UNION to also select contacts that have phones where none are cell phones might work in theory, but I'm not aware of NHibernate HQL supporting UNION. Even then, you'd have to select explicit NULLs as placeholders for the missing cell phone, and as previously mentioned, I don't think NHibernate HQL supports selecting literal NULLs.
Even if a "join to top 1 wrong row and map with SELECT CASE" or a UNION approach is possible in HQL, we have monster queries that have upwards of 30 joins, 5 or more of which need correct "LEFT JOIN with additional join criteria" behavior. Any workarounds would produce horrendous queries. Even if our developers would put up with it, our product is customizable and our customers can write their own HQL queries, and they wouldn't accept workarounds with such large and tricky amounts of extra query logic.
In any case, if you can come up with single NHibernate 1.2 HQL query that can return the correct results for the "contact and optional cell phone" example I gave, let me know. It needs to behave like this:
1. If the contact has no cell phone, the contact is returned with a NULL for the phone.
2. If the contact has cell phone(s), the contact is returned with cell phone, for each cell phone.
3. If the contact has any non-cell phone(s), that should not affect the behavior of #1 or #2.