nhibernate - 基于表达式的限制 [英] nhibernate - restriction based on an expression
本文介绍了nhibernate - 基于表达式的限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用nHibernate Criteria,而且我坚持认为应该很简单。在SQL中它将是:
WHERE startPos + length> 17
(startPos和length是表中的两列)。任何人都可以帮助我用nHibernate实现这一点
解决方案这是如何在NHibernate中使用Criteria实现的:
var criteria = session.CreateCriteria< MyEntity>(); // C#MyEntity
criteria.Add(
//添加限制
Restrictions.Gt(
//左边部分作为投影
Projections.SqlProjection (
(startPos + length)as myAlias
,new [] {myAlias}
,new IType [] {NHibernateUtil.Boolean})
//右部分
,17
));
I am using nHibernate Criteria and I'm stuck on something that seems like it should be really simple. in SQL it would be:
WHERE startPos + length > 17
(startPos and length are two columns on the table). Can anyone help me achieve this with nHibernate
解决方案
This is the way how to do that with Criteria in NHibernate:
var criteria = session.CreateCriteria<MyEntity>(); // C# MyEntity
criteria.Add(
// add restriction
Restrictions.Gt(
// left part as a projection
Projections.SqlProjection(
"(startPos + length) as myAlias"
, new[] {"myAlias"}
, new IType[] {NHibernateUtil.Boolean} )
// right part
, 17
));
这篇关于nhibernate - 基于表达式的限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文