What if you get two objects and save 2 times? Tuna Toksöz Eternal sunshine of the open source mind.
http://devlicio.us/blogs/tuna_toksoz http://tunatoksoz.com http://twitter.com/tehlike On Fri, Sep 18, 2009 at 1:39 AM, Sravan Kumar < [email protected]> wrote: > I am following unit of work pattern. UI tier calls Business tier to get an > entiy with ID. > > Gettting an objec with ID is Unit Of work in this example. I Get an entity > bind it to UI and then do some modifications and then calls > > Save. Save is a another unit of work. > > Thank you very much . > Sravan > > On Thu, Sep 17, 2009 at 6:33 PM, Tuna Toksoz <[email protected]> wrote: > >> Opening a session in every operation is bad. You loose unit of work + >> first level cache etc. Don't do it. >> >> >> >> Tuna Toksöz >> Eternal sunshine of the open source mind. >> >> http://devlicio.us/blogs/tuna_toksoz >> http://tunatoksoz.com >> http://twitter.com/tehlike >> >> >> >> >> >> On Thu, Sep 17, 2009 at 9:31 PM, sravan >> <[email protected]>wrote: >> >>> >>> I have a Get Method that takes the ID of the entity and gives the >>> object with that ID. >>> >>> In the Get Method I open a new session and calls Get on the session. >>> >>> the first call to get takes 10 sec, but subsequent calls to get takes >>> just 2 seconds. >>> >>> I do not have second level caching enabled. >>> >>> I ran the sql server profiler and it is taking the same time to >>> execute the query in both the cases. >>> >>> Not able to figure out why it is taking so long time for first call to >>> get. >>> >>> Any help is Greatly appreciated. >>> >>> The second call is invoked on a different session. >>> >>> public virtual T Get( long ID ) >>> { >>> >>> if ( null == Interceptor ) throw new TechnicalException >>> ( "RepositoryBase::Get: ERROR: Interceptor must be set prior to use of >>> this class." ); >>> >>> T entity = null; >>> using ( ISession session = >>> NHibernateSessionFactorySingleton.GetSession( Interceptor ) ) >>> { >>> using ( ITransaction transaction = >>> session.BeginTransaction( ) ) >>> { >>> >>> session.FlushMode = >>> FlushMode.Never; >>> >>> T entity = session.Get<T>( ID ); >>> >>> transaction.Commit( ); >>> } >>> >>> } >>> >>> >>> return entity; >>> } >>> >>> >>> Sravan >>> >>> >> >> >> --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "nhusers" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/nhusers?hl=en -~----------~----~----~----~------~----~------~--~---
