Search code examples
nhibernatequeryover

How to do more than one level projection in query over?


I tired this

respondentSanctionSubquery = respondentSanctionSubquery.Select(x => x.Respondent.Incident.Id);

but i got this exception : enter image description here

i have 3 entities not 2 entities :

class Respondent
{
public IncidentObj{get;set;}
}
class Incident
{
public int Id{get;set;}
}
class RespondentSanction
{
public Respondent RespondentObj{get;set;}
}

Solution

  • you should do join between the entities using Join alias

    respondentSanctionSubquery = 
        respondentSanctionSubquery
            .JoinAlias(x => x.RespondentObj)
            .JoinAlias(resp => resp.IncidentObj)
            .Select(inc => inc.Id);
    

    for more information please check this URL :What is the difference between JoinQueryOver and JoinAlias?