how to retrieve a single column’s value of type string using HQL.
I tried the following way but is not working.
public virtual string GetCityById(int Id)
{
using (var session = sessionFactory.OpenSession())
{
using (var transaction = session.BeginTransaction())
{
var queryString = string.Format("SELECT C.CityName FROM {0} AS C WHERE Id=:Id", typeof(T));
return session.CreateQuery(queryString).SetInt32("Id", Id).ToString(); <--Also tried with .SetParameter("Id",Id)
}
}
}
Expected Output is:
NEWYORK
Actual Output is:
Select Name FROM FNHHelper.Entites.Cities WHERE Id=:Id
You’re returning the String representation of the query. You just need to execute the query, and return its unique result:
(assuming the method name is the same as in the Java version).