我已经用 NHibernate3 声明了休闲映射:
使用 FluentNHibernate
public class ActivityMap : ClassMap<Activity> {
public ActivityMap() {
this.Table("Activity");
this.Cache.ReadWrite();
this.Version(x => x.ObjectVersion);
this.Id(x => x.Id).GeneratedBy.Assigned();
// snipp
this.HasOne(x => x.AppointmentRecurrence).Cascade.Delete();
}
}
public class AppointmentRecurrenceMap : ClassMap<AppointmentRecurrence> {
public AppointmentRecurrenceMap() {
this.Table("AppointmentRecurrence");
this.Cache.ReadWrite();
this.Version(x => x.ObjectVersion);
this.Id(x => x.Id).GeneratedBy.Foreign("Activity");
// snipp
this.HasOne(x => x.Activity).Constrained();
}
}
它正在生成闲置的 hbm 映射:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class xmlns="urn:nhibernate-mapping-2.2" lazy="false" name="Prayon.Entities.Activity, Prayon.Entities, Version=1.0.0.867, Culture=neutral, PublicKeyToken=null" table="Activity">
<cache usage="read-write" />
<id name="Id" type="System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Id" />
<generator class="assigned" />
</id>
<!-- snipp -->
<one-to-one cascade="delete" class="Prayon.Entities.AppointmentRecurrence, Prayon.Entities, Version=1.0.0.867, Culture=neutral, PublicKeyToken=null" foreign-key="FK_Activity_AppointmentRecurrence" name="AppointmentRecurrence" />
</class>
</hibernate-mapping>
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2">
<class xmlns="urn:nhibernate-mapping-2.2" lazy="false" name="Prayon.Entities.AppointmentRecurrence, Prayon.Entities, Version=1.0.0.867, Culture=neutral, PublicKeyToken=null" table="AppointmentRecurrence">
<cache usage="read-write" />
<id name="Id" type="System.Guid, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089">
<column name="Id" />
<generator class="foreign">
<param name="property">Activity</param>
</generator>
</id>
<!-- snipp -->
<one-to-one class="Prayon.Entities.Activity, Prayon.Entities, Version=1.0.0.867, Culture=neutral, PublicKeyToken=null" constrained="true" foreign-key="FK_AppointmentRecurrence_Activity" name="Activity" />
</class>
</hibernate-mapping>
现在,当我选择活动(带有可缓存选择)时,我在 NHibernate-Profiler 中看到,NHibernate 正在从二级缓存中正确获取每个活动,但它会为每个活动选择 AppointmentReccurrence。我该怎么办,它也会从缓存中获取 AppointmentRecurrence ?我曾尝试在一对一关系上设置缓存属性,但似乎不受支持。