[英]how to make modulo by criteriaBuilder for NHibernate to be executed in SqlLite
I need to verify if the value of a field is even , I use SqlLite as Database, I tryed with 我需要验证字段的值是否均匀,我使用SqlLite作为数据库,我尝试过
var sqlf= Projections.SqlFunction(“mod”, NHibernateUtil.Int32, Projections.ProjectionList().Add(Projections.Property(nameof(GsProcedure.Number))).Add(Projections.Constant(“2”)));
criteriaBuilder.Add(Restrictions.Eq(sqlf, 0)); criteriaBuilder.Add(Restrictions.Eq(sqlf,0));
but this create a request like this: “WHERE mod(this_.PRO_NO AS y0_, 2) = 0” and it is not executable by sqlLite which accepts only “where PRO_NO%2=0” Do you know what should I do? 但是这会创建一个这样的请求:“WHERE mod(this_.PRO_NO AS y0_,2)= 0”并且它不能由sqlLite执行,它只接受“where PRO_NO%2 = 0”你知道我该怎么办?
var sqlf= Projections.SqlFunction(“mod”, NHibernateUtil.Int32, Projections.ProjectionList().Add(Projections.Property(nameof(GsProcedure.Number))).Add(Projections.Constant(“2”))); var sqlf = Projections.SqlFunction(“mod”,NHibernateUtil.Int32,Projections.ProjectionList()。Add(Projections.Property(nameof(GsProcedure.Number)))。Add(Projections.Constant(“2”))); criteriaBuilder.Add(Restrictions.Eq(sqlf, 0));
criteriaBuilder.Add(Restrictions.Eq(sqlf,0));
but this create a request like this: “WHERE mod(this_.PRO_NO AS y0_, 2) = 0” and it is not executable by sqlLite which accepts only “where PRO_NO%2=0” 但是这会创建一个这样的请求:“WHERE mod(this_.PRO_NO AS y0_,2)= 0”并且它不能由sqlLite执行,它只接受“where PRO_NO%2 = 0”
You shouldn't wrap projection parameters for Projections.SqlFunction
in ProjectionList
: 您不应该在
ProjectionList
包装Projections.SqlFunction
的ProjectionList
参数:
var sqlf= Projections.SqlFunction(
"mod",
NHibernateUtil.Int32,
Projections.Property(nameof(GsProcedure.Number)),
Projections.Constant("2"));
Other than that your query looks correct and should work since NHibernate 3.2. 除此之外,您的查询看起来正确并且应该自NHibernate 3.2起作用。 Please make sure that you use
SQLiteDialect
in your session factory configuration. 请确保在会话工厂配置中使用
SQLiteDialect
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.