用于修改生成的 SQL 语句的自定义 NHibernate 实体持久化器
我需要的是从数据库视图(不可插入)填充实体并将所有实体更新到可更新的数据库表。
- 将实体映射到表并从视图编写自定义加载 SQL 不是一个选项,因为在某些情况下 NHibernate 仍会尝试从表名称中进行选择(例如,在加入此实体时)。
- 将实体映射到视图并编写自定义数据修改查询不是一个选项,因为我无法编写跨数据库 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.
- 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).
- 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论