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…

  1. Create a new class library project named CustomLinqGenearatorExample.
  2. Install the NHibernate and log4net packages using the NuGet Package Manager Console by executing the following command:
    Install-Package NHibernate
    Install-Package log4net
    
  3. Create the DateTimeFunctionsGenerator class using the following code:
    public class DateTimeFunctionsGenerator : BaseHqlGeneratorForMethod { public DateTimeFunctionsGenerator() { SupportedMethods = new[] { ReflectionHelper.GetMethod<DateTime>( ...

Get NHibernate 4.x Cookbook - Second Edition now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.