如何在C#的NHibernate的QueryOver中使用Oracle的内置关键字或函数?

时间:2016-09-20 13:00:45

标签: c# nhibernate queryover

我使用Oracle作为数据库。 如何在NHibernate的QueryOver中转换以下hibernate查询。

string condition = "RepositoryItemDO.RepositoryType = :REPTYPE AND 
24*(SYSDATE-RepositoryItemDO.FingerPrint.CreatingDateTime) >= :HOURS"
                    + " AND RepositoryItemDO.TargetEncryption IS NOT NULL AND RepositoryItemDO.TargetStorage IS NOT NULL";

如何在QueryOver中编写上述查询的语法?

1 个答案:

答案 0 :(得分:1)

您可以使用VarArgsSQLFunction在QueryOver中使用算术运算,并且对于访问sysdate,我们可以使用已在OracleDilect中定义的NoArgSQLFunction。

以下是您可以尝试使用queryover

的示例查询
var func = Projections.SqlFunction(new VarArgsSQLFunction(NHibernateUtil.Double, "(", "-", ")"), NHibernateUtil.DateTime, Projections.SqlFunction("sysdate", NHibernateUtil.DateTime), Projections.Property<AdministrativeCaseEO>(c => c.EffectiveCasePeriod.EffectiveStartDate));

var parfunc = Projections.SqlFunction(new VarArgsSQLFunction(NHibernateUtil.Double, "(", "*", ")"), NHibernateUtil.Decimal, func, Projections.Constant(24));

var conjunction = Restrictions.Conjunction()
.Add(Restrictions.Eq(Projections.Property<RepositoryItemDO>(c => c.RepositoryType ), yourRefType))
.Add(Restrictions.IsNotNull(Projections.Property<RepositoryItemDO>(c => c.TargetEncryption)))
.Add(Restrictions.IsNotNull(Projections.Property<RepositoryItemDO>(c => c.TargetStorage)))
.Add(dateConj);