我在中等信任下运行的应用程序中映射继承时遇到问题。当我从 web.config 中删除中等信任限制时,它就像一个魅力。如果我注释掉我的子类映射,一切都会很顺利。
当我的应用程序以中等信任启动时,在 Fluent 的配置构建期间,我捕获了异常,我可以从中读取 System.Runtime.Serialization.Formatters.Binary.ObjectWriter.Serialize(...) 方法没有运行权限。
我能找到的每一点信息都建议预先生成延迟代理、关闭延迟加载和禁用反射优化器。我已经完成了所有准备工作,如果我不映射子类,我的代码就可以工作。
这是我的映射:
public PageMap()
{
Id(x => x.PageID);
Map(x => x.DateCreated);
Map(x => x.DateLastAccessed);
Map(x => x.Hits);
Map(x => x.PrivateSuffix);
Map(x => x.PublicSuffix);
HasMany(x => x.Components).Not.LazyLoad();
Not.LazyLoad();
}
}
public class ComponentMap: ClassMap<Component>
{
public ComponentMap()
{
Id(x => x.ComponentID);
Map(x => x.Position);
References(x => x.Page);
DiscriminateSubClassesOnColumn("ComponentType");
Not.LazyLoad();
}
}
public class HeadingComponentMap : SubclassMap<HeadingComponent>
{
public HeadingComponentMap()
{
Map(x => x.Text);
Not.LazyLoad();
}
}
以及来自 web.config 的相关部分
<hibernate-configuration xmlns="urn:nhibernate-configuration-2.2">
<bytecode-provider type="null"/>
<reflection-optimizer use="false" />
<session-factory name="">
<property name="connection.provider">NHibernate.Connection.DriverConnectionProvider</property>
<property name="connection.driver_class">NHibernate.Driver.SqlClientDriver</property>
<property name="connection.connection_string">data source=.\SQLEXPRESS;Integrated Security=SSPI;AttachDBFilename=|DataDirectory|entities.mdf;User Instance=true</property>
<property name="dialect">NHibernate.Dialect.MsSql2008Dialect</property>
<property name='proxyfactory.factory_class'>NHibernate.ByteCode.Castle.ProxyFactoryFactory, NHibernate.ByteCode.Castle</property>
<property name='current_session_context_class'>web</property>
</session-factory>
我必须手动完成所有操作吗?我非常想在这里使用继承。