NHibernate Forge
The NHibernate community site.

Pre-Generate Lazy Loading Proxies

Comments (2)
History (11)
100% of people found this useful

Pre-Generate Lazy Loading Proxies

Filed under: [Edit Tags]


  1. Download the latest binaries for NHibernate ProxyGenerators
  2. Extract the binaries to your "lib" directory relative to your source files
  3. Open a command prompt and navigate the to "bin" directory in your web project.
  4. Enter the following command:
    ..\..\..\lib\bin\net-2.0\NHPG.exe /o:Example.Domain.Proxies.dll Example.Domain.dll

    NHPG.exe:  The console application that generates the proxies.  Included in the binary distribution from step 1
    /o: The path to the assembly that will be generated by NHPG
    Example.Domain.dll: The assembly that contains your NHibernate Mappings (hbm.xml files)
  5. Add 'proxyfactory.factory_class' to your NHibernate configuration file:
    <hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
    <property name="dialect">NHibernate.Dialect.MsSql2000Dialect</property>
    <property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
    <property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
    <property name="connection.connection_string">Server=(local);Database=Development;Trusted_Connection=True;</property>
    <mapping assembly="Example.Domain" />

    <property name="proxyfactory.factory_class">CastleStaticProxyFactoryFactory, Example.Domain.Proxies</property>
    Replace Example.Domain.Proxies with the name of the assembly used for argument '/o' in Step 4.
  6. You're done!  Pre-generated lazy loading proxies can be used with NHibernate to Run in Medium Trust 

Sample Commands

  • Generate proxies for ActiveRecord
    NHPG.exe /g:activerecord /o:Example.ActiceRecordDomain.Proxies.dll Example.ActiveRecordDomain.dll
  • Generate proxies with multiple class mapping assemblies
    NHPG.exe /o:Example.Domain.Proxies.dll Example.Domain1.dll Example.Domain2.dll
  • Generate proxies with a custom Dialect
    NHPG.exe /d:
    NHibernate.Dialect.Oracle9Dialect /o:Example.Domain.Proxies.dll Example.Domain.dll

Recent Comments

By: Bill Pierce Posted on 10-09-2008 11:51

<p>JIRA added - <a rel="nofollow" target="_new" href="jira.nhibernate.org/.../p>

By: insect Posted on 10-09-2008 4:33

<p>How About using it with Nhibernate Mapping Attributes?</p>

View More
Powered by Community Server (Commercial Edition), by Telligent Systems