Abd El Rahman Mohammed
Abd El Rahman Mohammed

Reputation: 107

NHibernate Eager Loading

In Entity Framework when i disable lazy loading and proxy, associations will never be loaded until i include them explicitly.

How can i get the same behavior in NHibernate?

I Tried to set lazy = false in the mapping config file associations are loaded which is completely opposite behavior of entity framework

 <set name="associations" table="parentChild" lazy="false">
 ......
 </set>

Is there a way to get entity framework like behavior

Upvotes: 1

Views: 150

Answers (2)

Fr&#233;d&#233;ric
Fr&#233;d&#233;ric

Reputation: 9854

If your aim is to avoid those properties to be proxied, see Hazzik answer. This causes the holding entity to be proxied instead.

If your aim is to be able to access those properties without them being loaded, staying (wrongly according to actual data in db) null (null or empty for collections), NHibernate does not provide a feature for this, excepted not mapping those properties (which of course will not allow eager loading either).

If it is the later, why do you need this? Maybe should you ask another question about what causes you to want that and how to solve it (maybe without that).

Upvotes: 0

hazzik
hazzik

Reputation: 13344

It seems that you are looking for lazy=no-proxy option, it gives the closest result to what you want to achieve.

lazy (optional - defaults to proxy): by default, single point associations are proxied. lazy="no-proxy" specifies that the property should be fetched lazily when the instance variable is first accessed. It requires build-time bytecode instrumentation. lazy="false" specifies that the association will always be eagerly fetched.

(from Hibernate docs, but still applies to NHibernate)

Upvotes: 1

Related Questions