How to perform a query in HQL in C #?

1

I need to create an HQL query inside a C # method. The structure looks something like this: I have the method:

IList<int>GetListYear(Guid educationalInstitutionId, Guid academicLevelId, Guid? locationId, Guid? programOfferedId)
{
    //Implementar a consulta HQL
} 

And I have the query in HQL:

"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"

How can I set up this structure in order to join the HQL query with the parameters I received from my method?

    
asked by anonymous 11.06.2015 / 17:03

1 answer

3

face would look something like this:

IList<int> GetListYear(Guid educationalInstitutionId, Guid academicLevelId, Guid? locationId, Guid? programOfferedId)
{
    StringBuilder hql = new StringBuilder();

    hql.Append(" select distinct ConclusionYear ");
    hql.Append(" from AlumniProgramOffered ");
    hql.Append(" inner join AlumniSignup ");
    hql.Append(" inner join ProgramOffered ");
    hql.Append(" inner join Program ");
    hql.Append(" where AlumniSignup.EducationalInstitution.Identity = :educationalInstitutionId ");
    hql.Append(" and Program.AcademicLevel.Identity = :academicLevelId ");
    hql.Append(" and ProgramOffered.Location.Identity = :locationId or locationId is null ");
    hql.Append(" and ProgramOffered.Identity = :programOfferedId or programOfferedId is null" ");

    Query query = Session.CreateHqlQuery(hql.ToString());
    query.SetParameter("educationalInstitutionId", educationalInstitutionId);
    query.SetParameter("academicLevelId", academicLevelId);
    query.SetParameter("locationId", locationId);
    query.SetParameter("programOfferedId", programOfferedId);

    return query.ToList<int>();
} 
    
11.06.2015 / 20:32