In this recipe, we will show how you can add mappings for database functions, which are not available by default.
Create a new class library project named
CustomDialectExample
.Install the
NHibernate
andlog4net
packages using the NuGet Package Manager Console by executing the following command:Install-Package NHibernate Install-Package log4net
Create a new class named
CustomMsSql2012Dialect
using the following code:public class CustomMsSq2012Dialect: MsSql2012Dialect { public CustomMsSq2012Dialect() { RegisterFunction("AddDays", new SQLFunctionTemplate( NHibernateUtil.DateTime, "dateadd(day,?2,?1)")); RegisterFunction("AddHours", new SQLFunctionTemplate( NHibernateUtil.DateTime, "dateadd(hour,?2,?1)")); RegisterFunction("AddMinutes", new SQLFunctionTemplate( NHibernateUtil.DateTime, "dateadd(minute,?2,?1)")); RegisterFunction("AddSeconds", new SQLFunctionTemplate...