Let me guess: You are loading _MANY_ objects? If you then have
FlushMode.Auto NHibernate will dirty check all objects already loaded
in the ISession for every subsequent query. As you notice towards the
end, this isn't affected much by transaction or not.

You can try with FlushMode.Commit (and one single transaction instead
of one for each call) or even FlushMode.Never since this is readonly.
Or you can try with IStatelessSession.

For reports, one could also think about whether to use queries with
projections of the actual data needed, instead of loading the
entities. Can be faster, but it makes logic in the entity classes
unavailable when building the report.

/Oskar


2010/10/26 Luca7993 <[email protected]>:
> Hi
> I read almost everywhere that I always should begin and commit
> nhibernate transaction even if we make a reading query.
> but I have a strange problem using explicit transactions and I think
> there is something that I haven't understood with Nhibernate and
> transactions:
>
> I have sql server on my machine.
> In my windows application, I have to create a report and I follow this
> steps (I'm using NHibernate 3.0 beta):
>
> -create and open a session
> -get a list of items A with a GetAll
> -I have a loop for each A item, and take a list of B items filtered by
> A (from database)
> -after that i create a file excel.
> -close the session
>
>
> I'm using always the same session for everything.
> the getall is wrapped in a nhibernate transaction (using tx =
> session.begintransaction() ..... tx.Commit())
> as I read, I should wrap in a transaction also each query that take
> list of B items.
> But if I wrap in transactions, the performance slow down at each
> passage in the loop...the query takes about 10ms..after 20-30 times,
> it takes about 100ms...after 100 times about 200ms and go on...(the
> effective cost of query is still about 10ms)
> If I don't wrap the queries in transactions (but always using the same
> session),everything is ok and each query alwyas takes about 10ms...
>
>
> If I use instead, different session for each calls to retrieve B
> items, even if I use transaction, there is no problem.
>
> I tried to disable the second cache, but it's always the same
>
>
> which is my mystake?
>
> thank you
>
> --
> 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.
>
>

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