我有一個nHibernate父子表關係。父類當前正在將子元素拉入列表中,但我想將它們放入基於表中排序列的SortedList中。如何更改NHibernate映射文件以讓系統知道我正在訂購哪一列?如何映射到NHibernate中的SortedList
目前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?
沒有錯過的東西...謝謝 –
很高興看到它的工作! –