用于修改生成的 SQL 语句的自定义 NHibernate 实体持久化器

发布于 2024-09-30 05:31:13 字数 534 浏览 0 评论 0原文

我需要的是从数据库视图(不可插入)填充实体并将所有实体更新到可更新的数据库表。

  1. 将实体映射到表并从视图编写自定义加载 SQL 不是一个选项,因为在某些情况下 NHibernate 仍会尝试从表名称中进行选择(例如,在加入此实体时)。
  2. 将实体映射到视图并编写自定义数据修改查询不是一个选项,因为我无法编写跨数据库 sql-insert 语句(因为最后插入的标识值选择部分)。

我现在想到的唯一想法是即时修改生成的 SQL 语句。我设法使用自定义拦截器来做到这一点,但我认为这不是一个好主意(因为我拦截了每个查询,即使对于其他实体也是如此)。但是,我认为应该可以使用自定义 IEntityPersister 更改仅需要的查询。我基于 SingleTableEntityPersister 创建了一个,并在 中指定了它,但 NHibernate 甚至不想实例化它。

有没有为 NHibernate 编写自定义实体持久化程序的示例?

What I need is to populate entity from DB view (non-insertable) and make all entity updates to updatable DB table.

  1. Mapping entity to table and writing custom load SQL from view is not an option since in some cases NHibernate still tries to select from table name (when joining this entity, for example).
  2. Mapping entity to view and writing custom data modification queries is not an option since I can not write cross-database sql-insert statement (because of the last inserted identity value selection part).

The only idea I came up with for now is to modify generated SQL statements on-the-fly. I managed to do it with custom interceptor but I don't think that its a good idea (since I intercept every single query, even for other entities). However, I think that it should be possible to change only needed queries using custom IEntityPersister. I created one based on SingleTableEntityPersister, specified it in <class persister="…">, but NHibernate doesn't even want to instantiate it.

Are there any examples of writing custom entity persisters for NHibernate?

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文