views:

27

answers:

1

This is my unit test (it's quite meaningless but proves a point

Config entity = new Config("key", "value");

Session.SaveOrUpdate(entity);

Config config = Session.Query<Config>().SingleOrDefault(c => c.Key == "key");
Assert.IsNotNull(config);

it fails...but I don't think it should (note, if I flush it, it doesn't fail, but that's not the behaviour I want)

If I replace the query line with this

Config config = Session.Get<Config>("key");

...it passes

At no point does it flush (I even set the FlushMode to never just to be sure). Why would one be successful, and the other not? This doesn't seem right - and I would very much like the linq one to be successful

+4  A: 

This article:

http://ayende.com/Blog/archive/2009/04/30/nhibernate-ndash-the-difference-between-get-load-and-querying-by.aspx

Seems to suggest that a Query will go to the database, bypassing the session's cache, whereas Get will try the session first.

Greg Fleming
Wow, good find! If you're using Query caching (I'm not sure how you do this) does this mean .Query and .Get would return the same thing?
Paul