开发者

Custom NHibernate entity persister for modifying generated SQL statements

开发者 https://www.devze.com 2023-01-22 20:45 出处:网络
What I need is to populate entity from DB view (non-insertable) and make all entity updates to updatable DB table.

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 NHiber开发者_开发问答nate doesn't even want to instantiate it.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消