Sorry, I'm not making myself clear. I understand that UoW has a FlushMode of commit. The bit that I don't understand is *why do I need to flush*. It looks to me that Rhino UoW uses the same session as Rhino Repository, so should be able to 'see' unsaved / unflushed / uncommitted entities in the session cache. Obviously I am wrong (because the behaviour does not reflect this) but I am trying to understand why I am wrong - I suspect that Respository<T>.Save and UnitOfWork.Current.Linq are in fact using entirely different sessions?
From: [email protected] [mailto:[email protected]] On Behalf Of Ayende Rahien Sent: 23 March 2009 16:45 To: [email protected] Subject: [rhino-tools-dev] Re: Session cache, Repository and Linq2Nh That is because I am explicitly setting the session.FlushMode to CommitOnly This means that a query is not going to cause a flush. That, in turn, means that it is not there for the db to find the value. since NH has not idea what the expected values are, it can't figure out that it already has this value, and you get empty On Mon, Mar 23, 2009 at 12:42 PM, Junior <[email protected]> wrote: But from what I understand, I shouldnt need to flush at all. If you are using the same session, you have previous saves / updates in the session cache, so queries will retrieve objects from the cache without needing to flush to the db. This is why I don't need to flush before calling "Car car = Repository<Car>.Get(1)". Why does the same not apply to calling "from car in UnitOfWork.CurrentSession.Linq<Car> ... etc"? (this is all happening in the same code block) On Mar 23, 4:38 pm, Ayende Rahien <[email protected]> wrote: > Rhino Tools set the flush mode to commit, instead of auto.This is why you > are seeing that. > > On Mon, Mar 23, 2009 at 11:47 AM, Junior <[email protected]>wrote: > > > > > > > Hi all, > > > I am trying to understand session management in Rhino Commons > > Repository<T> and UnitOfWork, I have tried my best at understanding > > the source code, but feel I am misunderstanding some concepts. Briefly > > my problem is this: > > > I save an entity using Repository<T>: > > Repository<Car>.Save(new Car{Id = 1}); > > > I can then retrieve the car like so: > > Car car = Repository<Car>.Get(1); > > > Thanks to the Session cache, the car is retrieved without having to > > flush the session / commit a tx / write to the database. > > However when I then try to query Car using NHibernate Linq provider: > > > IQueryable<Car> cars = (from car in UnitOfWork.CurrentSession.Linq<Car> > > () > > select car); > > > I get nothing, unless I explicity flush the session / commit a tx > > after saving the car. I understand that UoW requires you to commit the > > transaction before it writes the changes to the db. However as I also > > understand from looking at the Rhino Commons source code and the > > NHibernate Contrib code, I should not have to do this (flush the > > changes) as the Linq provider will use the same session and thus > > should be able to 'see' the session cache: > > > NHRepsoitory uses this: > > > protected virtual ISession Session > > { > > get { return UnitOfWork.CurrentSession; } > > } > > > And NHibernateExtensions Linq method is also passed > > UnitOfWork.CurrentSession. So my question is this - is this the > > expected behaviour (having to flush a repository save before using > > Linq to NHibernate)? If so, why? Or am I misunderstanding something > > and need to take a deeper look into the code? > > > Many thanks for any help! > > > James- Hide quoted text - > > - Show quoted text - ______________________________________________________________________ This email has been scanned by the MessageLabs Email Security System. For more information please visit http://www.messagelabs.com/email ______________________________________________________________________ Save paper, please think twice before printing this email. Newcastle Technopole | Kings Manor | Newcastle upon Tyne | NE1 6PA T. 0191 201 2111 | F. 0191 201 2127 | Service Desk Direct Line. 0191 201 2121 Perfect Image Ltd. Registered in England & Wales. Company Registration Number: 2650067 Registered Office: Newcastle Technopole, Kings Manor, Newcastle upon Tyne NE1 6PA This e-mail is confidential and intended solely for the use of the individual to whom it is addressed. Any views or opinions presented are solely those of the author and do not represent those of Perfect Image Ltd. If you are not the intended recipient, please notify us at [email protected] and be advised that you have received this mail in error and that any use, dissemination, forwarding, printing or copying of this e-mail is strictly prohibited. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Rhino Tools Dev" 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/rhino-tools-dev?hl=en -~----------~----~----~----~------~----~------~--~---
