I am writing a web app using Castle ActiveRecord, and I keep getting this exception whenever I try to access a lazy loaded list of related objects. Here is my code:
using(new SessionScope())
{
foreach (var field in eventObj.RegistrationFields)
{
//Do something with the field here...
}
}
The RegistrationFields property looks like this:
[HasMany(Inverse = true, Lazy = true)]
public IList<EventRegistrationField> RegistrationFields { get; set; }
The exception happens when the "eventObj.RegistrationFields" is accessed for the foreach loop. I also made sure to set the isweb="true" attribute in my activeRecord config settings. Does anyone know why this would happen? Here is my config:
<connectionStrings>
<add name="main" connectionString="Data Source=localhost\SQLEXPRESS;Initial Catalog=EventScheduler;Integrated Security=SSPI"/>
</connectionStrings>
<activerecord isWeb="true">
<config>
<add key="hibernate.connection.driver_class" value="NHibernate.Driver.SqlClientDriver"/>
<add key="hibernate.dialect" value="NHibernate.Dialect.MsSql2005Dialect"/>
<add key="hibernate.connection.provider" value="NHibernate.Connection.DriverConnectionProvider"/>
<add key="hibernate.connection.connection_string_name" value="main"/>
</config>
</activerecord>