C# NHibernate支持函数:LEN
我想得到结果:C# NHibernate支持函数:LEN,c#,nhibernate,C#,Nhibernate,我想得到结果: select * from Cate where LEN(code)=2 我的代码: var filter1 = Restrictions.Eq( Projections.SqlFunction("LEN", NHibernateUtil.Int32, Projections.Property("code")), 2); var quer
select * from Cate where LEN(code)=2
我的代码:
var filter1 = Restrictions.Eq(
Projections.SqlFunction("LEN", NHibernateUtil.Int32,
Projections.Property("code")), 2);
var query =
repository.Session.QueryOver<Cate>().Where(filter1).List();
Assert.IsTrue(query.Count > 0);
var filter1=Restrictions.Eq(
Projections.SqlFunction(“LEN”,NHibernateUtil.Int32,
(1)财产(“代码”)、2);
变量查询=
repository.Session.QueryOver().Where(filter1.List();
Assert.IsTrue(query.Count>0);
但是,也有一些错误:
NHibernate.hibernate异常:当前方言
NHibernate.dialogue.mssql2008dialogue不支持函数:LEN
如何在Nhibernate中使用Len函数的SQLServer2008?您应该在Configuration类中注册函数
config.AddSqlFunction("len", new StandardSafeSQLFunction("len", NHibernateUtil.Int32, 1));
或者创建一种自定义方言
public class MyDialect : MsSql2008Dialect
{
public MyDialect()
{
RegisterFunction("len", new StandardSafeSQLFunction("len", NHibernateUtil.Int32, 1));
}
}
使用
length
代替len
。这就是它在方言中的注册方式