我有一个 nHibernate 父子表关系。父类当前正在将子类拉入 List 但我想根据表中的排序列将它们放入 SortedList 中。如何更改 NHibernate 映射文件以让系统知道我正在订购哪一列?
当前的 NHibernate 映射文件是:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Model.Configuration.Pages"
assembly="Model.Configuration">
<joined-subclass
table="PageConfigurations"
name="PageConfiguration"
extends="Model.Configuration.Configuration.TargetedConfiguration"
lazy="false">
<key column="TargetedConfigurationId" />
<property name="SchemaVersion" />
<property name="Template" type="System.String" length="50" />
<property name="PageKey" type="System.String" length="50" />
<property name="Percentage" />
<bag name="Controls" cascade="all-delete-orphan" lazy="false" >
<key column="PageConfigurationId" />
<one-to-many class="WidgetConfiguration"/>
</bag>
</joined-subclass>
</hibernate-mapping>
对于父表和:
<hibernate-mapping xmlns="urn:nhibernate-mapping-2.2"
namespace="Model.Configuration.Pages"
assembly="Model.Configuration">
<class name="WidgetConfiguration" lazy="false" table="PageConfiguration_Widgets" discriminator-value="Default">
<id name="Id" unsaved-value="0" type="int" >
<generator class="identity" />
</id>
<discriminator column="ConfigurationType" />
<property name="Slot" type="System.String" length="100" />
<property name="WidgetTypeName" type="System.String" length="100"/>
<property name="ViewName" type="System.String" length="50" />
<property name="SlotOrder" type="System.Int32" />
</class>
</hibernate-mapping>
对于子表。
在将 WidgetConfiguration 提取到 SortedList 时,我需要向父映射或子映射添加什么以让他们知道新的 SlotOrder 列应用作关键字段。
编辑:数据被读入的类是:
public class PageConfiguration : TargetedConfiguration
{
public PageConfiguration()
{
// replaced by SortedList
//Controls = new List<WidgetConfiguration>();
Controls = new SortedList<int, WidgetConfiguration>();
}
public string PageKey { get; set; }
public string Template { get; set; }
public int? Percentage { get; set; }
// replaced by SortedList
//public IList<WidgetConfiguration> Controls { get; set; }
public IDictionary<int, WidgetConfiguration> Controls { get; set; }
public int SchemaVersion { get; set; }
}
请注意,List<WidgetConfiguration>
已更改为SortedList<int, WidgetConfiguration>
。我如何告诉 NHibernate,当将新项目添加到 SortedList 时,使用的键值应该是 WidgetConfiguration.SlotOrder?