I'm trying to write a query to select using the DateTime. Year as a where parameter, but I'm receiving this error from nunit:
NHibernate.QueryException : could not resolve property: Register.Year of: Estudantino.Domain.Events
In class Events I've a property named Register as a DateTime type.
public virtual DateTime Registada { get; set; }
This is the method that is returning the error:
using (ISession session = NHibernateHelper.OpenSession())
{
return session.QueryOver<Evento>()
.Where(x => x.Register.Year == year)
.List();
}
The variable year is of type int, that is been passed to the method.
Does anyone have an idea of what i'm doing wrong? My database server is SQL Server 2005 Express.
You may need to use HQL here instead. Basically NHibernate does not know really what to do with year
. I suspect you need to use the RegisterFunction
to register a YEAR
function.
Please read this article in its entirety to fully understand what it is you are trying to do.
MyYearFunction
that returns a year for a datewhere dbo.MyYearFunction(:date) = 12" ...