Pre-Generate Lazy Loading Proxies
 Article
|
|
|
100% of people found this useful
- Download the latest binaries for NHibernate ProxyGenerators
- Extract the binaries to your "lib" directory relative to your source files

- Open a command prompt and navigate the to "bin" directory in your web project.
- 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)
- 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.
- 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