我使用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中编写上述查询的语法?
答案 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);