自定义一个Dialect, 然后再NHibernate的配置文件中使用此Dialect即可.
然后再 linq 里面可以直接使用
MyPostgreSQLDialect.date_trunc
using NHibernate;
using NHibernate.Dialect;
using NHibernate.Dialect.Function;
using NHibernate.Linq;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace MyProject.Biz
{
public class MyPostgreSQLDialect : PostgreSQL82Dialect
{
static log4net.ILog log = log4net.MyLogManager.GetCurrentNamespaceLogger();
public MyPostgreSQLDialect()
{
RegisterFunction("date_trunc", new StandardSQLFunction("date_trunc", NHibernateUtil.Date/*函数的返回值*/));
}
[LinqExtensionMethod]
public static DateTime date_trunc(string type, DateTime time)
{
throw new NotImplementedException();//无需具体实现. 即可在 NHibernate.Linq中使用了.
}
}
}