Profiling Session.Load and Session.Delete

4 views
Skip to first unread message

Morten Maxild

unread,
Sep 14, 2009, 8:37:34 AM9/14/09
to nhp...@googlegroups.com

Hi,,

 

I am doing (inside a commited transacton)

 

var x = session.Load<SomeRoot>(12);

session.Delete(x);

 

and I am seeing a SELECT ….WHERE Id=12 from the Load. I thought Load would give me a proxy, and then only a DELETE would result. But NHProf is showing both a SELECT and then a DELETE

 

Kind regards

Maxild

Ayende Rahien

unread,
Sep 14, 2009, 8:51:00 AM9/14/09
to nhp...@googlegroups.com
Is SomeRoot lazy?

Morten Maxild

unread,
Sep 14, 2009, 8:51:03 AM9/14/09
to nhp...@googlegroups.com

Good question…Yes

 


Ayende Rahien

unread,
Sep 14, 2009, 9:00:10 AM9/14/09
to nhp...@googlegroups.com
If it is, then NH can't lazy load it and has to hit the DB immediately

Morten Maxild

unread,
Sep 14, 2009, 9:13:01 AM9/14/09
to nhp...@googlegroups.com

I am not following, maybe my ignorance

 

If its lazy, shouldn’t Load give me a proxy, always?

 

If I am only doing s.Delete(s.Load(12)), shouldn’t only a delete (for perf reasons) be performed by NH?

 

/Morten

Ayende Rahien

unread,
Sep 14, 2009, 9:22:05 AM9/14/09
to nhp...@googlegroups.com
No, if it isn't lazy, NH have to go to the DB to get the values, because you explicitly said that you don't want a proxy when you marked the class as not lazy.
As for s.Delete(s.Load(12)); NH would load the data anyway, even if the class is lazy, to handle cascades.

Morten Maxild

unread,
Sep 14, 2009, 9:44:28 AM9/14/09
to nhp...@googlegroups.com

No, if it isn't lazy

It is lazy, I want Load to give me proxy. I have now verified the correct behaviour using NHProf, thanks.

As for s.Delete(s.Load(12)); NH would load the data anyway, even if the class is lazy, to handle cascades.”

Makes sense for entities with associations to other entities controlled by cascade options, but what if the entity doesn’t have associations, or the associations doesn’t cascade?

 

In my small investigation the Delete(Load)-statement would generate a SELECT even if the entity had no associations.

 

P.S.

 

Maybe this thread is for the nhusers list?

Ayende Rahien

unread,
Sep 14, 2009, 9:51:56 AM9/14/09
to nhp...@googlegroups.com
I think that it is more appropriate there, yes.

Morten Maxild

unread,
Sep 14, 2009, 9:57:02 AM9/14/09
to nhp...@googlegroups.com

I moved it there

Reply all
Reply to author
Forward
0 new messages