I need to get the Objects used in a NHibernate Session, that were modified after loading.
The Session Provides the Property IsDirty indicating weather Objects were modified in the Session or not. I Need a Method that Returns me the Objects causing IsDirty to return true.
If you could provide a bit of C# Code to fulfill this Task I would be very greatful.
Based on the comments of JBL my code to find all "dirty" objects
var dirtyObjects = new List<object>();
var sessionImpl = hsession.GetSessionImplementation();
foreach (NHibernate.Engine.EntityEntry entityEntry in sessionImpl.PersistenceContext.EntityEntries.Values)
{
var loadedState = entityEntry.LoadedState;
var o = sessionImpl.PersistenceContext.GetEntity(entityEntry.EntityKey);
var currentState = entityEntry.Persister.GetPropertyValues(o, sessionImpl.EntityMode);
if (entityEntry.Persister.FindDirty(currentState, loadedState, o, sessionImpl) != null)
{
dirtyObjects.Add(entityEntry);
}
}
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With