This question is close to but not the same as the one here: NHibernate Query across multiple tables
Basically, my question is given the following model, how would I query to find out if the current dog has the name "foo" or a past dog has the name "foo" (disjunction). Essentially I have a Many-To-One relationship for CurrentDog and a Many-To-Many relationship for PastDogs.
public class Dog {
public string name {get; set;}
}
public class Owner {
public string firstname {get; set;}
public string lastname {get; set;}
public Dog CurrentDog {get; set;}
public Dog[] PastDogs {get; set;}
}
I'd guess the SQL should look something like this:
SELECT o.* FROM owners AS o
INNER JOIN dogs AS cd ON o.current_dog_id = cd.id
INNER JOIN owner_past_dog_maps AS pd ON o.id = pd.owner_id
INNER JOIN dogs AS d ON pd.dog_id = d.id
WHERE d.name = 'foo'
OR cd.name = 'foo'
Hope that makes sense... I'll try clarify it if anyone asks.