让 NHibernate 对 DateTime.Date 使用 TRUNC

发布于 2025-01-06 02:10:14 字数 514 浏览 2 评论 0原文

我有一个具有 DateTime 属性的实体,该实体映射到 Oracle 数据库中的表。

以下查询导致 NHibernate 使用不存在的 date 函数而不是 trunc

session.Query<MyEntity>().Where(x => x.MyProperty.Date = myDate);

生成的 SQL 类似于:

select <columns> from MY_ENTITY where date(MY_PROPERTY) = :p0;

如何告诉 NHibernate 使用 trunc< /代码> 代替?

我正在使用 NHibernate 的 ODP.NET 提供程序 (OracleDataClientConfiguration.Oracle10)。

I have an entity with a DateTime property that is mapped to a table in an Oracle database.

The following query leads to NHibernate using a non-existent date function instead of trunc:

session.Query<MyEntity>().Where(x => x.MyProperty.Date = myDate);

The resulting SQL is something like this:

select <columns> from MY_ENTITY where date(MY_PROPERTY) = :p0;

How to tell NHibernate to use trunc instead?

I am using the ODP.NET provider of NHibernate (OracleDataClientConfiguration.Oracle10).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

云裳 2025-01-13 02:10:14

此问题大约一个月前已修复,但尚未发布稳定版本(截至 2012 年 2 月 15 日),

在此之前,只需继承 Oracle10gDialect 并注册构造函数中的函数:

RegisterFunction("date", new StandardSQLFunction("trunc", NHibernateUtil.Date));

然后配置 NH 使用修改后的方言。

This issue was fixed about a month ago, but a stable version hasn't been released yet (as of 15/Feb/2012)

Until that happens, just inherit from Oracle10gDialect and register the function in the constructor:

RegisterFunction("date", new StandardSQLFunction("trunc", NHibernateUtil.Date));

Then configure NH to use the modified dialect.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文