【发布时间】:2013-07-12 20:09:45
【问题描述】:
如何使用 NHibernate(最好是 QueryOver 语法)来获取以下 SQL
SELECT this_.Name as_, count(IsNull(this_.Name , 'UNKNOWN') ) as NameCount
FROM...
【问题讨论】:
标签: sql nhibernate queryover isnull
如何使用 NHibernate(最好是 QueryOver 语法)来获取以下 SQL
SELECT this_.Name as_, count(IsNull(this_.Name , 'UNKNOWN') ) as NameCount
FROM...
【问题讨论】:
标签: sql nhibernate queryover isnull
在 NHibernates sql 方言中不支持 IsNull,但 Coalesce 支持,并且对于两个参数来说是一样的。
你可以的
Projections.SqlFunction("Coalesce", NHibernateUtil.String,
Projections.Property("Name"), Projections.Constant("UNKNOWN"))
获得与 IsNull() 等效的投影。
【讨论】:
Projections.Conditional
在 ICriteria 中有 NHibernate.Criterion.Restrictions.IsNull(PropertyName) 我想你也可以在 QueryOver 中使用它 -
var qOver = QueryOver.Of<MyEntity>(() => meEntity);
qOver = qOver.Where(Restrictions.IsNull(PropertyName));
【讨论】: