In this case, the Select
clause is an issue for NHibernate. It expects the property (during the expression tree parsing) to be converted into SELECT statement. But there is a method call: .ToString()
.
One way how to solve it, could be explicit Projection
like this (see doc QueryOver 16.6. Projections)
var reportingGroupYears = session
.QueryOver<ReportingGroup>()
.Where(x => x.Number == request.ReportingGroupNumber)
.Select(Projections.ProjectionList()
.Add(Projections.Cast(NHibernateUtil.String, Projections.Property("Year"))
))
.List<string>();