Creating a Custom NHibernate SQL Object

A somewhat simplified example situation: I have entities A and B, which are incredibly “heavy” domain objects. Downloading one of the databases is a pretty big deal. Then I have an entity C, which is a very simple object that has a label string, one A and one B - both are lazy.

I make some low-level queries to create huge C lists, so I know exactly which identifiers I need to save for CA and CB, but I don’t want to load whole objects and set them on properties because the overhead is crazy.

Instead, I want to simply insert the identifiers directly into my C objects, and then let the properties A and B on it be fully loaded later, only if necessary.

I see the tag <sql-insert/>in the documentation, but the section is really sparse.

Is there a way to do what I want to do within NHibernate, or just do raw SQL? I am trying to maintain database portability if possible, which makes me shy away from the raw option. It seems like I better miss.

+3
source share
2 answers

I don’t know if NHibernate allows this (separate objects on the same underlying data), but usually I do a “digest” of objects that can be converted to full-scale objects (even when loading lazily onto full-scale objects), I usually do this using gengen code or manual ORM layers.

, , , , , ..

+1

- , , . , , C, (--, ), = "false" update = "false" (, cascade = "none" ). " " A B, , C C (Session.SaveOrUpdateCopy(C)). , NHibernate A B , C - A B.

, A B, . , , , .

+1

Source: https://habr.com/ru/post/1698451/


All Articles