Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add multiple joins (Fetches) to a joined table using nhibernate and LINQ?

i have these tables /entities

VacationRequestDate table which has a VacationRequestId field that links with VacationRequest table
VacationRequest has PersonId and RequestStatusId fields that links with Person and RequestStatus respectively.

i have this query so far:

IEnumerable<VacationRequestDate> dates = Session.Query<VacationRequestDate>().Fetch(r => r.VacationRequest).ThenFetch(p=>p.RequestStatus).ToList();

this works fine and joins with VacationRequest and then VacationRequest joins with RequestStatus but i can't figure out how to add an additional EAGER join to the VacationRequest table.

If i add a Fetch at the end, it refers to the VacationRequestDate table
If i add a ThenFetch at the end, it refers to the RequestStatus table

I can't find any api that will refer to the VacationRequest table as the reference point.

how would you add multiple joins to a joined table using nhibernate LINQ ?

like image 744
leora Avatar asked Dec 04 '25 06:12

leora


1 Answers

While not 100% optimal because of an additional join, this works:

Session.Query<VacationRequestDate>()
       .Fetch(r => r.VacationRequest).ThenFetch(p => p.RequestStatus)
       .Fetch(r => r.VacationRequest).ThenFetch(p => p.Person)

The other querying methods (HQL, Criteria, not sure about QueryOver) don't have this limitation.

like image 131
Diego Mijelshon Avatar answered Dec 05 '25 22:12

Diego Mijelshon