For my current project I'm learning NHibernate and I have trouble translating the below query
select person.Firstname, person.Lastname
from Person
inner join Contract on contract.PersonId = person.Id
inner join Budget on budget.ContractId = contract.Id
inner join Choice on choice.BudgetId = budget.Id
inner join ChosenBenefit on ChosenBenefit.ChoiceId = choice.Id
where ChosenBenefit.BenefitImplementationId = 77
I thought the below would do the trick, but I get a nullreference with a stacktrace I can't make head or tails from.
Choice choice = null;
Budget budget = null;
Contract contract = null;
Person person = null;
var peopleThatChose = Session.QueryOver<ChosenBenefit>()
.JoinAlias(chosenBenefit => chosenBenefit.Choice, () => choice)
.JoinAlias(chosenBenefit => choice.Budget, () => budget)
.JoinAlias(chosenBenefit => budget.Contract, () => contract)
.JoinAlias(chosenBenefit => contract.Person, () => person)
.Where(chosenBenefit => chosenBenefit.BenefitImplementation.Id == 77)
.Select(benefit => person);
From all the examples everywhere, it seams I'm supposed to QueryOver<Person>
, but then I can't work my way down to where I want to put my restriction.
What am I missing?