SQL Functions day, year, month not working in JetDialect

Description

the JetDialect has some strange ways to try to extract the year(month, day) part of an datetime:

crit.Add(Restrictions.Eq(Projections.SqlFunction("Year", NHibernateUtil.DateTime, Projections.Property("lastChanged")), filter.LastChanged.Year));

adds some "and (extract year from ?)" to the sql. This does not work in M$ Access.
To fix this add

RegisterFunction("year", new SQLFunctionTemplate(NHibernateUtil.DateTime, "year(?1)"));
RegisterFunction("month", new SQLFunctionTemplate(NHibernateUtil.DateTime, "month(?1)"));
RegisterFunction("day", new SQLFunctionTemplate(NHibernateUtil.DateTime, "day(?1)"));

to the JetDialect
After that all worked like a charm

Environment

None

Activity

Show:

Alex Zaytsev 
May 19, 2017 at 1:32 AM

ThomasT 
September 17, 2009 at 10:13 AM

Silly me. Should be:
RegisterFunction("year", new SQLFunctionTemplate(NHibernateUtil.Int32, "year(?1)"));
RegisterFunction("month", new SQLFunctionTemplate(NHibernateUtil.Int32, "month(?1)"));
RegisterFunction("day", new SQLFunctionTemplate(NHibernateUtil.Int32, "day(?1)"));

Details

Assignee

Reporter

Components

Affects versions

Priority

Who's Looking?

Open Who's Looking?
Created July 22, 2009 at 12:00 AM
Updated May 19, 2017 at 1:32 AM
Who's Looking?