Not loading associations without proxies in NHibernate
Posted
by Alice
on Stack Overflow
See other posts from Stack Overflow
or by Alice
Published on 2010-05-20T19:55:18Z
Indexed on
2010/05/20
21:30 UTC
Read the original article
Hit count: 238
nhibernate
I don't like the idea of proxy and lazy loading. I don't need that. I want pure POCO. And I want to control loading associations explicitly when I need.
Here is entity
public class Post
{
public long Id { get; set; }
public long OwnerId { get; set; }
public string Content { get; set; }
public User Owner { get; set; }
}
and mapping
<class name="Post">
<id name="Id" />
<property name="OwnerId" />
<property name="Content" />
<many-to-one name="Owner" column="OwnerId" />
</class>
However if I specify lazy="false" in the mapping, Owner is always eagerly fetched. I can't remove many-to-one mapping because that also disables explicit loading or a query like
from x in session.Query<Comment>()
where x.Owner.Title == "hello"
select x;
I specified lazy="true" and set use_proxy_validator property to false. But that also eager loads Owner.
Is there any way to load only Post entity?
© Stack Overflow or respective owner