That is because I am explicitly setting the session.FlushMode to CommitOnlyThis 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 - > > > --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---
