views:

438

answers:

3

I have used NHibernbate in few projects and now learned about few more ORMs also. I understand that, NHibernate binds Class to Datalayer dynamically during runtime using the mapping file.

My Question is , how this late binding is done ? I mean, which Methodology is used, 'Reflection' or 'DynamicMethod' ?

In case, if it uses Reflection, Is there any ORM which uses DynamicMethod? and provides better performance ?

+1  A: 

NHibernate uses Castle.DynamicProxy, which under the hood uses DynamicMethods.

jonnii
even if you specify your class as 'lazy' ?
Frederik Gheysels
@Frederik: 'lazy' is what tells NHibernate to proxy the entity with Castle.DynamicProxy. Otherwise it's not proxied.
Mauricio Scheffer
IIRC nhibernate makes classes lazy by default.
jonnii
@jonnii: yep, unless you define it otherwise (default-lazy="false" or lazy="false")
Mauricio Scheffer
A: 

Exactly how an ORM instantiates entities is not a good way to assess its overall performance.

James L
agreed, but it doesn't answer the question....
Mauricio Scheffer
@James L: Hand-written CRUD fan? ;)
dario-g
@dario-g no just like to keep a close eye on my ORM
James L
+2  A: 

As of NHibernate 2.1, the proxy factory is pluggable. Here are some proxy providers supported:

  • Castle.DynamicProxy
  • LinFu
  • Spring.NET

So proxying will be actually out of NHibernate's responsibility, and the answer to this question really depends on the selected proxy factory.

Mauricio Scheffer