Extending the LINQ provider
Sometimes you will need a more sophisticated way to translate method calls to HQL. In this recipe, we will show you how to implement a custom LINQ to HQL generator that is able to do this.
Getting ready
Complete the Using custom dialect functions recipe.
How to do it…
- Create a new class library project named
CustomLinqGenearatorExample
. - Install the
NHibernate
andlog4net
packages using the NuGet Package Manager Console by executing the following command:Install-Package NHibernate Install-Package log4net
- Create the
DateTimeFunctionsGenerator
class using the following code:public class DateTimeFunctionsGenerator : BaseHqlGeneratorForMethod { public DateTimeFunctionsGenerator() { SupportedMethods = new[] { ReflectionHelper.GetMethod<DateTime>( d => d.AddDays(0)), ReflectionHelper.GetMethod<DateTimeOffset>( d => d.AddDays(0)), ReflectionHelper.GetMethod<DateTime>( d => d.AddHours...