The session-cache is used only when the entityIdentity is know.When you
execute a query NH hit DB for the whole query, then, before create each
entity instance, NH hit the session-cache to know if some one is available
in which case the available instance will be used.

If you want cache a entirely query result you should use the Cache (aka
second-level-cache).

2009/3/2 Graham Bunce <[email protected]>

>
> Hiya,
>
> A developer on my team raised an issue today and it threw me a little
> as the behaviour he reported wasn't was I was expecting.
>
> He is running through a loop, doing an HNibernate Linq query (which
> resolves down to a Critera query). Based on the results he either adds
> or updates then, once all objects are processed he does a Flush.
>
> (psuedo code)
>
> foreach entity
>    Run Linq Query to match on entity.surname= "xyz"   //i.e. not the
> key value
>    if query.count ==0
>        Session.Add(entity)
>    else
>        Get the First entity from the query (i.e. results.First()  )
>        Update values
>        Session.Update(entity)
> endfor
>
> Session.Flush()
>
> The Linq/Critera query is hitting the DB each time instead of checking
> the Session first to see if the object exists in the session already.
> Therefore if a second entity is hit in the foreach, with the same
> surname, the Linq query hits the DB again and doesn't find it as the
> Flush hasn't taken place yet.
>
> I may be answering my own question here but...
>
> Is NHibernate hitting its own session before running the linq query
> but not finding a match so runs the Query? If so,how does it identify
> a match in its own 1st level cache?
> >
>


-- 
Fabio Maulo

--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to