Logo

NHibernate

The object-relational mapper for .NET

ProxyGenerators

This page is converted from the old nhforge.org Wiki. First published by: Bill Pierce on 09-22-2008, Last revision by: John Davidson on 09-07-2011

Pre-Generate Lazy Loading Proxies

 

  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">
     
    <session-factory>
       
    <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>
     
    </session-factory>
    </
    hibernate-configuration>
    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
© NHibernate Community 2024