Not working: Lazy FetchWhen.OnInvoke (Parent Child, Heirarchy)

67 views
Skip to first unread message

William Chang

unread,
Aug 10, 2009, 6:28:25 PM8/10/09
to Castle Project Users
Here is my model setup:
I have two entities, "List" and "ListItem". The "List" class is the
parent with the property "public virtual List listParent {get;set;}"
to create the hierarchy. The "ListItem" class is the child or
children, containing items for the list.

The problem is when I do a Find() on an item from the "ListItem"
class, it pulls everything from above. The "List", the parent, gets
joined which is okay, but then it pulls the grand parent list, and so
on. How do I prevent or stop NHibernate/Activerecord from parsing up
the tree (not needed, hurting performance)?

I tried using "Lazy" in my "List" class:
[ActiveRecord(Table = "Lists")]
public class List : ActiveRecordBase<List> {
[BelongsTo("listParentId", Lazy = FetchWhen.OnInvoke)]
public virtual List listParent {get;set;}
}

And, I tried using "Lazy" in my "ListItem" class:
[ActiveRecord(Table = "ListItems")]
public class ListItem : ActiveRecordBase<ListItem> {
[BelongsTo("itemListId", Lazy = FetchWhen.OnInvoke)]
public virtual List itemList {get;set;}
}

Please help?

Specs:
NHibernate 2.1.0GA
Castle ActiveRecord 2.0
ASP.NET 3.5 SP1 MVC 1.0

Thanks,
William Chang

Markus Zywitza

unread,
Aug 11, 2009, 1:32:39 AM8/11/09
to castle-pro...@googlegroups.com
AR has the problem that if you don't use SessionScopes, it can't use lazy loading at all. Therefore lazy loading was disabled by default. AFAIR you have to set lazy="true" in your AR config to enable lazy loading of many-to-one relations.

-Markus

2009/8/11 William Chang <dieha...@gmail.com>

Gerdus van Zyl

unread,
Sep 18, 2009, 4:31:10 AM9/18/09
to castle-pro...@googlegroups.com
I don't use sessionscopes (manage nh session myself gotten via AR) how
can I enable lazy loading again? I thought lazy loading was a
nhibernate feature, so what does AR do to disable it? Or just point me
to where in the code that happens.

thank you.

~Gerdus
Reply all
Reply to author
Forward
0 new messages