russuk wrote:
I’m using the following code to support a legacy view that contains an object
Code:
sql = string.Format(sql, EQUIPMENT_INSTALLATION_SELECT);
query.SetResultTransformer(NHibernate.Transform.Transformers.AliasToBean(typeof(EquipmentInstallation)));
I have checked the logs and also the objects and nothing has been changed so I am guessing that using the SetResultTransformer is in some way causing this to happen.
Any advice would be great
I'm not sure about SetResultTransformer, it should return an unmanaged entity and would therefore not be in the cache to flush. If the entity you are querying for is mapped I would think that it would be managed. IF the type you are loading is unmanaged, I would think you'd need SetResultTransformer with AliasToBean along with metadata to help NHibernate with the mapping (like Projections with ICriteria). Again, I'm not sure.
It certainly sounds as if you have the queried entities in the cache and I can't help but wonder if you have a mapping file defined for the class and are using SetResultTransformer to populate a managed entity. If this was the case then I'd guess that NHibernate config knows about your class and is caching the result of your query, in which case subsequent flushes would attempt and update. These are only guesses though.
I do understand that you are reading from a view, so would want a read only context. I know a simpler way to approach this.
I would open a separate session for the call to the view and set
newSession.FlushMode = FlushMode.Never;
When you open this new session you can pass the connection from the current session into the OpenSession method.
ISession newSession = sessionFactory.OpenSession(currentSession.Connection);
Once you query the view and get your results, call newSession.Dispose();
At this point your results are no longer associated with a session and you haven't done any Flush()s.
Hope that helps.