gpt4 book ai didi

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

转载 作者:太空宇宙 更新时间:2023-11-03 12:39:21 24 4
gpt4 key购买 nike

我正在使用 Oracle 作为数据库。如何在NHibernate的QueryOver中转换following hibernate query。

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 中编写上述查询的语法?

最佳答案

您可以使用 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);

关于c# - 如何在 C# 中的 NHibernate 的 QueryOver 中使用 Oracle 的内置关键字或函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/39594835/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com