Using NHibernate in a Medium Trust web environment requires the following:
- All referenced assembiles must be marked with AllowPartiallyTrustedCallers
- Web.config configSections must be marked with requirePermission="false"
<configSections>
<section name="hibernate-configuration" requirePermission="false" type="NHibernate.Cfg.ConfigurationSectionHandler, NHibernate"/>
<section name="log4net" requirePermission="false" type="log4net.Config.Log4NetConfigurationSectionHandler, log4net" />
...
</configSections>
- Reflection optimization must be disabled
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<reflection-optimizer use="false" />
...
</hibernate-configuration>
- Default lazy loading must be disabled on all class mappings
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2" assembly="Example.Domain" namespace="Example.Domain.Models" default-lazy="false">
<class name="Person">
...
</class>
</hibernate-mapping>
Alternativly you could pre-generate lazy loading proxies using NHibernate ProxyGeneators.