cremor wrote:
You can mark readonly entities with mutable="false" in your mapping.
You can remove an entity from the session with session.Evict()
I tried mutable="false" which would have been the most fitting solution but it didn't help at all. Will try to find something in the documentation about it.
Will try session.Evict() did actually work really nice after settings cascade="all-delete-orphan". I would really like to use this in a more global way. I guess I create an ReadOnlyNHibernateRepository. :)
How does FlushMode.Never works?
My problem is that I try to retrieve an object from the database, work with it and do some changes to it and just not save the changes to the database.
I pass an SessionProvider that implements an ISessionProvider interface to my repository that provides me with sessions to work with.
First I used my normal session provider and then I thought I could make something like this but it didn't work out too well.
Code:
From my NHibernateManager:
public ISession GetReadOnlySession
{
get
{
ISession session = GetFactory.OpenSession(GetSession.Connection);
session.FlushMode = FlushMode.Never;
return session;
}
}
Destructor in ReadOnlyNHibernateSessionProvider:
~ReadOnlyNHibernateSessionProvider()
{
NHibernateManager.GetInstance.GetReadOnlySession.Dispose();
}
public ISession GetCurrentSession
{
get
{
return NHibernateManager.GetInstance.GetReadOnlySession;
}
}
Any thoughts about the code? :)
Cheers,
Yagami