Using custom functions in LINQ
In this recipe, we will show you how to map database functions and stored procedures to LINQ functions.
Getting ready
Complete the previous recipe, Using custom dialect functions.
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
SqlFunctions
class using the following code:public static class SqlFunctions { [LinqExtensionMethod] public static DateTime AddDays(DateTime dt, int d) { return dt.AddDays(d); } [LinqExtensionMethod] public static DateTime AddHours(DateTime dt, int h) { return dt.AddHours(h); } [LinqExtensionMethod] public static DateTime AddMinutes(DateTime dt, int m) { return dt.AddMinutes(m); } [LinqExtensionMethod] public static DateTime AddSeconds(DateTime dt, int s) { return dt.AddSeconds...