我正在使用 Castle ActiveRecord 编写一个 Web 应用程序,每当我尝试访问延迟加载的相关对象列表时,我都会收到此异常。这是我的代码:
using(new SessionScope())
{
foreach (var field in eventObj.RegistrationFields)
{
//Do something with the field here...
}
}
RegistrationFields 属性如下所示:
[HasMany(Inverse = true, Lazy = true)]
public IList<EventRegistrationField> RegistrationFields { get; set; }
当为 foreach 循环访问“eventObj.RegistrationFields”时会发生异常。我还确保在我的 activeRecord 配置设置中设置了 isweb="true" 属性。有谁知道为什么会发生这种情况?这是我的配置:
<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>