Thanks. I'm understanding a bit of Hibernate. So, any pointers on how do I make my class to have this DATEPART thing? Or am I in the right track?
I added 2 public properties and map it
Code:
public int Month
{
get { return month; }
set { month = value; }
}
public int Year
{
get { return year; }
set { year = value; }
}
Code:
<property name="Month" formula="datepart(mm, Date)" insert="false" update="false"/>
<property name="Year" formula="datepart(yyyy, Date)" insert="false" update="false"/>
Now, I need help on the syntax of my HQL. How do I query given a Month and the Year? Sori for my noob questions but I try learning here. I really do. Again, thanks!
[edit]
Btw, I have
Code:
Find f = new Find("from Article where Month = 6 and Year = 2006");
f.Execute();
IList list = f.List;
foreach (Article a in list)
Console.WriteLine(a.Keyword);
But gives me
Code:
TestCase 'NBulletin.Commands.Test.CommandTest.TestFindArticles'
failed: NHibernate.ADOException : Could not execute query
----> System.Data.SqlClient.SqlException : Invalid column name 'Month'.
at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters)
at NHibernate.Impl.SessionImpl.Find(String query)
D:\ian\projects\csharp\nbulletin\src\NBulletin.Core\Commands\Commands.cs(138,0): at NBulletin.Commands.Find.Execute()
d:\ian\projects\csharp\nbulletin\src\nbulletin.core\commands\test\commandtest.cs(30,0): at NBulletin.Commands.Test.CommandTest.TestFindArticles()
--ADOException
at System.Data.SqlClient.SqlCommand.ExecuteReader(CommandBehavior cmdBehavior, RunBehavior runBehavior, Boolean returnStream)
at System.Data.SqlClient.SqlCommand.ExecuteReader()
at System.Data.SqlClient.SqlCommand.System.Data.IDbCommand.ExecuteReader()
at NHibernate.Impl.BatcherImpl.ExecuteReader(IDbCommand cmd)
at NHibernate.Loader.Loader.GetResultSet(IDbCommand st, RowSelection selection, ISessionImplementor session)
at NHibernate.Loader.Loader.DoQuery(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.DoQueryAndInitializeNonLazyCollections(ISessionImplementor session, QueryParameters queryParameters, Object optionalObject, Object optionalId, Object[] optionalCollectionKeys, Boolean returnProxies)
at NHibernate.Loader.Loader.List(ISessionImplementor session, QueryParameters queryParameters, ISet querySpaces, IType[] resultTypes)
at NHibernate.Hql.QueryTranslator.List(ISessionImplementor session, QueryParameters queryParameters)
at NHibernate.Impl.SessionImpl.Find(String query, QueryParameters parameters)
TestFixture failed:
]