开发者

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 li开发者_如何学编程nks 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 ?


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.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜