Question:
Guys, I'm having difficulties with HQL and C#. I have the following method:
public IList<int> GetListYear(Guid educationalInstitutionId, Guid academicLevelId, Guid? locationId, Guid? programOfferedId)
{
//Implementar o HQL
}
And I have the following query:
"select distinct ConclusionYear
from AlumniProgramOffered
inner join AlumniSignup
inner join ProgramOffered*
inner join Program
where AlumniSignup.EducationalInstitution.Identity = educationalInstitutionId
and Program.AcademicLevel.Identity = academicLevelId
and ProgramOffered.Location.Identity = locationId or locationId is null
and ProgramOffered.Identity = programOfferedId or programOfferedId is null"
I need, through HQL, to perform this query passing the parameters I get in my GetListYear method
Answer:
To be sure what this query would look like, you would need the code for all your entities. But your HQL query would probably look like this:
select distinct ConclusionYear as cy
from AlumniProgramOffered as apo
join apo.AlumniSignup as as
join as.ProgramOffered as po
join po.Location as loc
join po.Program as pr
join pr.AcademicLevel as al
join pr.EducationalInstitution as edu
where edu.Identity = :educationalInstitutionId
and al.Identity = :academicLevelId
and loc.Identity = :locationId or locationId is null
and po.Identity = :programOfferedId or programOfferedId is null
This, of course, is just the HQL query. The rest of the code for calling this HQL I'm assuming you already know how to do it.