NHibernate - How do I transfer persistent objects attached to a session?

I need to check the set of attached objects that will persist if I call Flush () in this session. (I write code that accesses the session as part of a common pipeline before saving, and it can be used in any number of contexts.)

I myself want a method similar to

mySession.GetPersistentEntities ()

so that I can check them out and do some preprocessing.

Does anyone know how to do this?

Thank,

Jeff

+3
source share
2 answers

No, NHibernate ISession doesn’t reveal anything like this. You can:

  • Track these instances yourself (not recommended)
  • Use standard NHibernate mechanisms:
    • (, IFlushEventListener, ISaveOrUpdateEventListener)
    • (IInterceptor.OnFlushDirty(), OnSave())
+4

"" :

ISession session;
var sessionContext = session.GetSessionImplementation().PersistenceContext;

foreach(var entity in sessionContext.EntitiesByKey.Values)
{
  // do anything with the entity
}

.

+2

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


All Articles